Opened 7 years ago

Closed 7 years ago

Last modified 3 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:

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@…> 7 years ago.
8825.diff (1.5 KB) - added by cgrady 7 years ago.

Download all attachments as: .zip

Change History (8)

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

comment:1 Changed 7 years ago by mtredinnick

  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 7 years ago by cgrady

comment:2 Changed 7 years ago by cgrady

  • 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 7 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 7 years ago 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.

comment:5 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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