#8841 closed (fixed)
ModelChoiceIterator does not work with multi table inheritance
Reported by: | hmarr | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | ||
Cc: | Marc Remolt, hmarr, flosch | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The bug appears in the child admin interface view, when you use multi table inheritance.
A ForeignKey selectbox shows the output of __unicode__() from the parent object for select values instead of the PK.
Example:
<option value="Foo">Foo</option>
instead of
<option value="6">Foo</option>
We fixed it with the following code in django.forms.models.ModelChoiceIterator:
def choice(self, obj): if self.field.to_field_name: try: key = getattr(obj, self.field.to_field_name).pk except AttributeError: key = getattr(obj, self.field.to_field_name) else: key = obj.pk return (key, self.field.label_from_instance(obj))
Change History (5)
comment:1 by , 16 years ago
Component: | Admin interface → Forms |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Cc: | added |
---|
comment:3 by , 16 years ago
Cc: | added |
---|
comment:4 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
I haven't verified the bug, but it looks like a real bug. I'm not sure if the fix is correct in case of a OneToOneField with a
to_field
different from the pk.