summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-09-03 22:45:33 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-09-03 22:45:33 +0000
commit75528786a9dcbba5c8df3f21f59ad1e01f1e9027 (patch)
tree028c7b30efaa06b5b9f820b582b34482fc4e98db
parentc949665678cb6fcdd92bcc2d256a5f85c9606d44 (diff)
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
-rw-r--r--django/forms/models.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index 3bc132a998..6024a1c6c8 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -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))