Opened 16 years ago

Closed 16 years ago

Last modified 13 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: dev
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: no UI/UX: no

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 (2)

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

Download all attachments as: .zip

Change History (8)

by Christofer Bernander <nospam@…>, 16 years ago

Attachment: admin_inherited_m2m.diff added

comment:1 by Malcolm Tredinnick, 16 years ago

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.

by Collin Grady, 16 years ago

Attachment: 8825.diff added

comment:2 by Collin Grady, 16 years ago

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 by Jacob, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

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 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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