Opened 17 years ago
Closed 17 years ago
#4937 closed (duplicate)
edit_inline for a reflexive m2m_intermediary
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | edit_inline m2m_intermediary | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This follows the m2m_intermediary pattern, but with associations, not between two different models, but between pairs of instances of the *same* model.
Given this Person model:
class Person(models.Model): first_name = models.CharField(maxlength = 100) last_name = models.CharField(maxlength = 100)
and associating pairs of persons, while adding some data:
class Association(models.Model): person = models.ForeignKey(Person, related_name='friend_of') associate = models.ForeignKey(Person, related_name='friends') some_data = models.IntegerField()
the admin interface for these models works correctly.
Now, to be able to add Associations while editing Persons, add
edit_inline and core to Association fields.
When adding them to both ForeignKey fields:
class Association(models.Model): person = models.ForeignKey(Person, related_name='friend_of', core=True, edit_inline=models.TABULAR) associate = models.ForeignKey(Person, related_name='friends', core=True, edit_inline=models.TABULAR) dummy = models.IntegerField()
this error comes out:
Traceback (most recent call last): File ".../django/template/__init__.py" in render_node 754. result = node.render(context) File ".../django/template/defaulttags.py" in render 134. nodelist.append(node.render(context)) File ".../django/contrib/admin/templatetags/admin_modify.py" in render 171. bound_related_object = relation.bind( context['form'], original, bound_related_object_class) File ".../django/db/models/related.py" in bind 129. return bound_related_object_class(self, field_mapping, original) File ".../django/contrib/admin/templatetags/admin_modify.py" in __init__ 138. for (i,field_mapping) in self.field_mappings.items() ] File ".../django/oldforms/__init__.py" in items 264. self.fill() File ".../django/oldforms/__init__.py" in fill 283. field = self.parent_manipulator[full_field_name] File ".../django/oldforms/__init__.py" in __getitem__ 28. raise KeyError, "Field %s not found\n%s" % ( field_name, repr(self.fields)) KeyError at /admin/person/add/ 'Field association.0.associate not found [FormField "first_name", FormField "last_name", FormField "association.0.id", FormField "association.0.person", FormField "association.0.dummy", FormField "association.1.id", FormField "association.1.person", FormField "association.1.dummy", FormField "association.2.id", FormField "association.2.person", FormField "association.2.dummy", FormField "association.0.id", FormField "association.0.person", FormField "association.0.dummy", FormField "association.1.id", FormField "association.1.person", FormField "association.1.dummy", FormField "association.2.id", FormField "association.2.person", FormField "association.2.dummy"]'
When adding edit_inline and core to the first ForeignKey field only:
class Association(models.Model): person = models.ForeignKey(Person, related_name='friend_of', core=True, edit_inline=models.TABULAR) associate = models.ForeignKey(Person, related_name='friends') dummy = models.IntegerField()
this other error come out:
Traceback (most recent call last): File ".../django/template/__init__.py" in render_node 754. result = node.render(context) File ".../django/template/defaulttags.py" in render 134. nodelist.append(node.render(context)) File ".../django/contrib/admin/templatetags/admin_modify.py" in render 171. bound_related_object = relation.bind( context['form'], original, bound_related_object_class) File ".../django/db/models/related.py" in bind 129. return bound_related_object_class(self, field_mapping, original) TypeError at /admin/person/add/ 'bool' object is not callable
This is an exact duplicate of #1939, sorry for not seeing it before.