summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAnubhav Joshi <anubhav9042@gmail.com>2014-06-30 18:43:35 +0530
committerTim Graham <timograham@gmail.com>2014-06-30 10:25:57 -0400
commitfd5897193f0bd8fa211885be5726f8e5613f3c08 (patch)
tree036e8e5b5e3041fda649bb013daf9d2ce44724e0 /django
parentadd78c58b5adb1d6e92cb5c998465442492d7bfb (diff)
Fixed problem with refs #10811.
When 'to_field' is specified with a FK, then we need to check the pk value the object.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/fields/related.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index ac53515c1b..cd592d587c 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -623,13 +623,13 @@ class ReverseSingleRelatedObjectDescriptor(object):
# Set the values of the related field.
else:
for lh_field, rh_field in self.field.related_fields:
- val = getattr(value, rh_field.attname)
- if val is None:
+ pk = value._get_pk_val()
+ if pk is None:
raise ValueError(
'Cannot assign "%r": "%s" instance isn\'t saved in the database.' %
(value, self.field.rel.to._meta.object_name)
)
- setattr(instance, lh_field.attname, val)
+ setattr(instance, lh_field.attname, getattr(value, rh_field.attname))
# Since we already know what the related object is, seed the related
# object caches now, too. This avoids another db hit if you get the