Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#8825 closed (fixed)

Inherited ManyToMany-fields does not appear in edit forms

Reported by: Christofer Bernander <nospam@…> Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: ManyToMany inheritance new_fields
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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


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)

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

Attachments (2)

admin_inherited_m2m.diff (609 bytes) - added by Christofer Bernander <nospam@…> 10 years ago.
8825.diff (1.5 KB) - added by Collin Grady 10 years ago.

Download all attachments as: .zip

Change History (8)

Changed 10 years ago by Christofer Bernander <nospam@…>

Attachment: admin_inherited_m2m.diff added

comment:1 Changed 10 years ago by Malcolm Tredinnick

milestone: 1.0
Needs tests: set
Triage Stage: UnreviewedAccepted

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.

Changed 10 years ago by Collin Grady

Attachment: 8825.diff added

comment:2 Changed 10 years ago by Collin Grady

Needs tests: unset

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

comment:3 Changed 10 years ago 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.

comment:4 Changed 10 years ago by Malcolm Tredinnick

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.

comment:5 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(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.

comment:6 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top