diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index f986eea75b..df0f6ef538 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -210,8 +210,8 @@ class SingleRelatedObjectDescriptor(object): (value, instance._meta.object_name, self.related.get_accessor_name(), self.related.opts.object_name)) - # Set the value of the related field - setattr(value, self.related.field.rel.get_related_field().attname, instance) + # Set the value of the related field to the value of the related object's related field + setattr(value, self.related.field.attname, getattr(instance, self.related.field.rel.get_related_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 diff --git a/tests/modeltests/one_to_one/models.py b/tests/modeltests/one_to_one/models.py index 20ac7a5573..e25e33bcc0 100644 --- a/tests/modeltests/one_to_one/models.py +++ b/tests/modeltests/one_to_one/models.py @@ -79,6 +79,8 @@ DoesNotExist: Restaurant matching query does not exist. >>> r.place +>>> p2.id +2 # Set the place back again, using assignment in the reverse direction. >>> p1.restaurant = r