Skip to content

Commit

Permalink
Fixed #8841 -- Fixed a case of ForeignKeys to models constructed with
Browse files Browse the repository at this point in the history
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.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8957 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Sep 3, 2008
1 parent c949665 commit 7552878
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django/forms/models.py
Expand Up @@ -570,7 +570,13 @@ def __iter__(self):


def choice(self, obj): def choice(self, obj):
if self.field.to_field_name: 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: else:
key = obj.pk key = obj.pk
return (key, self.field.label_from_instance(obj)) return (key, self.field.label_from_instance(obj))
Expand Down

0 comments on commit 7552878

Please sign in to comment.