Django

Code

Ticket #8825 (closed: fixed)

Opened 4 months ago

Last modified 4 months ago

Inherited ManyToMany-fields does not appear in edit forms

Reported by: Christofer Bernander <nospam@bernander.net> Assigned to: nobody
Milestone: 1.0 Component: django.contrib.admin
Version: SVN Keywords: ManyToMany inheritance new_fields
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Since revision [8855], inherited ManyToMany?-fields does not appear in edit forms on the admin site.

Example models.py:

from django.db import models
from django.contrib import admin

class Person(models.Model):
	name = models.CharField(max_length=64, blank=True, null=True)

class BaseClass(models.Model):
	person = models.ManyToManyField(Person, related_name="%(class)s_person", blank=True, null=True)
	text = models.CharField(max_length=64, blank=True, null=True)

class InheritedClass(BaseClass):
	status = models.CharField(max_length=64, blank=True, null=True)

admin.site.register(InheritedClass)

In the example above, the person field will appear in [8854], but disappear in [8855].

Attachments

admin_inherited_m2m.diff (0.6 kB) - added by Christofer Bernander <nospam@bernander.net> on 09/02/08 20:58:21.
8825.diff (1.5 kB) - added by cgrady on 09/02/08 21:51:00.

Change History

09/02/08 20:58:21 changed by Christofer Bernander <nospam@bernander.net>

  • attachment admin_inherited_m2m.diff added.

09/02/08 21:06:01 changed by mtredinnick

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests set to 1.
  • milestone set to 1.0.

At this point in the process we need test cases for this type of change. A test that shows many-to-many fields not being available on a child model before the patch and then available afterward. This shouldn't be an admin-specific phenomenon.

09/02/08 21:51:00 changed by cgrady

  • attachment 8825.diff added.

09/02/08 21:53:24 changed by cgrady

  • needs_tests deleted.

added a test that shows the missing item from the class._meta.many_to_many after [8855] - passes in [8854], passes again after patch is applied

this does seem to be unique to admin though, if the patch is unapplied, the ManyToManyField works fine in a shell, but isn't in the meta value for m2ms

though it probably affects ModelForm itself also, since it likely reads the many_to_many attribute

09/02/08 22:31:13 changed by jacob

Looks like this was a mistake I made in [8855]. I'll look at it in the morning if nobody else gets to it first.

09/03/08 00:50:43 changed by mtredinnick

The Django shell is often a bit too robust of an environment to test things like this. It sets everything up two or three times. The test suite is a better place to look for failures. The test I'm about to commit doesn't test the internal implementation, but, rather, the external interfaces. This is probably what cgrady was trying in the shell, but it fails quite immediately in the test suite.

09/03/08 00:53:51 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [8908]) Fixed #8825 -- Fixed a small error model field setup (on the model class) from r8855. Patch from Christofer Bernander. Test based on one from cgrady.


Add/Change #8825 (Inherited ManyToMany-fields does not appear in edit forms)




Change Properties
Action