Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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


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: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 75528786a9dcbba5c8df3f21f59ad1e01f1e9027 1 parent c949665
@malcolmt malcolmt authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 django/forms/
8 django/forms/
@@ -570,7 +570,13 @@ def __iter__(self):
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)
key =
return (key, self.field.label_from_instance(obj))
Please sign in to comment.
Something went wrong with that request. Please try again.