1. Luke Plant
  2. django

Commits

mtre...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 2274799

Fixed #8841 -- Fixed a case of ForeignKeys to models constructed with
inheritance.

This patch is uglier than it needs to be (see comment in patch) to ensure no
accidental bug is introduced just before 1.0. We'll clean it up later.

  • Participants
  • Parent commits cd8b1be
  • Branches default

Comments (0)

Files changed (1)

File django/forms/models.py

View file
  • Ignore whitespace
 
     def choice(self, obj):
         if self.field.to_field_name:
-            key = getattr(obj, self.field.to_field_name)
+            # FIXME: The try..except shouldn't be necessary here. But this is
+            # going in just before 1.0, so I want to be careful. Will check it
+            # out later.
+            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))