Ticket #10157: 10157_2.diff

File 10157_2.diff, 1.3 KB (added by dgouldin, 6 years ago)
  • django/db/models/fields/related.py

     
    210210                                (value, instance._meta.object_name,
    211211                                 self.related.get_accessor_name(), self.related.opts.object_name))
    212212
    213         # Set the value of the related field
    214         setattr(value, self.related.field.rel.get_related_field().attname, instance)
     213        # Set the value of the related field to the value of the related object's related field
     214        setattr(value, self.related.field.attname, getattr(instance, self.related.field.rel.get_related_field().attname))
    215215
    216216        # Since we already know what the related object is, seed the related
    217217        # object caches now, too. This avoids another db hit if you get the
  • tests/modeltests/one_to_one/models.py

     
    7979<Restaurant: Ace Hardware the restaurant>
    8080>>> r.place
    8181<Place: Ace Hardware the place>
     82>>> p2.id
     832
    8284
    8385# Set the place back again, using assignment in the reverse direction.
    8486>>> p1.restaurant = r
Back to Top