Changeset 2564
- Timestamp:
- 03/25/06 19:37:06 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/db/models/fields/related.py
r2552 r2564 98 98 raise AttributeError, "%s must be accessed via instance" % self.related.opts.object_name 99 99 # Set the value of the related field 100 setattr(value, self.related.field.attname, instance) 101 100 setattr(value, self.related.field.rel.get_related_field().attname, instance) 101 102 # Set the cache on the provided object to point to the new object 103 setattr(value, self.related.field.get_cache_name(), instance) 104 102 105 class ReverseSingleRelatedObjectDescriptor(object): 103 106 # This class provides the functionality that makes the related-object … … 143 146 # Set the cache to point to the new object 144 147 setattr(instance, self.field.get_cache_name(), value) 145 148 146 149 class ForeignRelatedObjectsDescriptor(object): 147 150 # This class provides the functionality that makes the related-object django/branches/magic-removal/tests/modeltests/one_to_one/models.py
r2437 r2564 56 56 DoesNotExist: Restaurant does not exist for {'place__pk': ...} 57 57 58 # Set the place using assignment notation. Because place is the primary key on Restaurant, 59 # the save will create a new restaurant 60 >>> r.place = p2 61 >>> r.save() 62 >>> p2.restaurant 63 Ace Hardware the restaurant 64 >>> r.place 65 Ace Hardware the place 66 67 # Set the place back again, using assignment in the reverse direction 68 # Need to reget restaurant object first, because the reverse set 69 # can't update the existing restaurant instance 70 >>> p1.restaurant = r 71 >>> r.save() 72 >>> p1.restaurant 73 Demon Dogs the restaurant 74 75 >>> r = Restaurant.objects.get(pk=1) 76 >>> r.place 77 Demon Dogs the place 78 58 79 # Restaurant.objects.all() just returns the Restaurants, not the Places. 80 # Note that there are two restaurants - Ace Hardware the Restaurant was created 81 # in the call to r.place = p2. This means there are multiple restaurants referencing 82 # a single place... 59 83 >>> Restaurant.objects.all() 60 [Demon Dogs the restaurant ]84 [Demon Dogs the restaurant, Ace Hardware the restaurant] 61 85 62 86 # Place.objects.all() returns all Places, regardless of whether they have
