mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #10157: correctly set the related objects pk when assigning a reverse OneToOne. Thanks, dgouldin.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10224 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -79,6 +79,8 @@ DoesNotExist: Restaurant matching query does not exist. | ||||
| <Restaurant: Ace Hardware the restaurant> | ||||
| >>> r.place | ||||
| <Place: Ace Hardware the place> | ||||
| >>> p2.id | ||||
| 2 | ||||
|  | ||||
| # Set the place back again, using assignment in the reverse direction. | ||||
| >>> p1.restaurant = r | ||||
|   | ||||
		Reference in New Issue
	
	Block a user