Created
January 25, 2013 21:06
-
-
Save tswicegood/4637847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py | |
index ae792a3..c18907c 100644 | |
--- a/django/db/models/fields/related.py | |
+++ b/django/db/models/fields/related.py | |
@@ -595,7 +595,10 @@ def create_many_related_manager(superclass, rel): | |
Returns the correct value for this relationship's foreign key. This | |
might be something else than pk value when to_field is used. | |
""" | |
- fk = self.through._meta.get_field(field_name) | |
+ try: | |
+ fk = self.through._meta.get_field(field_name) | |
+ except AttributeError: | |
+ return obj.pk | |
if fk.rel.field_name and fk.rel.field_name != fk.rel.to._meta.pk.attname: | |
attname = fk.rel.get_related_field().get_attname() | |
return fk.get_prep_lookup('exact', getattr(obj, attname)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment