From 75528786a9dcbba5c8df3f21f59ad1e01f1e9027 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Wed, 3 Sep 2008 22:45:33 +0000 Subject: [PATCH] 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 --- django/forms/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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))