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.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8957 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-09-03 22:45:33 +00:00
parent c949665678
commit 75528786a9
1 changed files with 7 additions and 1 deletions

View File

@ -570,7 +570,13 @@ class ModelChoiceIterator(object):
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))