Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

[1.0.X] Fixed #10157: correctly set the related objects pk when assig…

…ning a reverse OneToOne. Thanks, dgouldin.

Backport of r10224 from trunk.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent fd0c4bb commit 7475092c9facfdec98c6c01a7edbdaed53e4a07a @jacobian jacobian committed
4 django/db/models/fields/
@@ -203,8 +203,8 @@ def __set__(self, instance, value):
(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
2  tests/modeltests/one_to_one/
@@ -79,6 +79,8 @@ def __unicode__(self):
<Restaurant: Ace Hardware the restaurant>
<Place: Ace Hardware the place>
# Set the place back again, using assignment in the reverse direction.
>>> = r

0 comments on commit 7475092

Please sign in to comment.
Something went wrong with that request. Please try again.