Ticket #10672: 10672.diff
File 10672.diff, 5.2 KB (added by , 16 years ago) |
---|
-
django/db/models/base.py
416 416 override this method. It's separate from save() in order to hide the 417 417 need for overrides of save() to pass around internal-only parameters 418 418 ('raw' and 'cls'). 419 420 Returns True if the instance has been inserted, otherwise False if it 421 has been updated. 419 422 """ 420 423 assert not (force_insert and force_update) 421 424 if not cls: … … 439 442 if field and getattr(self, parent._meta.pk.attname) is None and getattr(self, field.attname) is not None: 440 443 setattr(self, parent._meta.pk.attname, getattr(self, field.attname)) 441 444 442 self.save_base(cls=parent)445 record_exists = not self.save_base(cls=parent) 443 446 if field: 444 447 setattr(self, field.attname, self._get_pk_val(parent._meta)) 445 if meta.proxy:446 return447 448 448 449 if not meta.proxy: 449 450 non_pks = [f for f in meta.local_fields if not f.primary_key] … … 494 495 signals.post_save.send(sender=self.__class__, instance=self, 495 496 created=(not record_exists), raw=raw) 496 497 498 return (not record_exists) 499 497 500 save_base.alters_data = True 498 501 499 502 def _collect_sub_objects(self, seen_objs, parent=None, nullable=False): -
tests/modeltests/force_insert_update/models.py
60 60 ... 61 61 DatabaseError: ... 62 62 63 # Model's internal save_base() method should return True on insert and False on update 64 >>> cc3 = Counter(name=u"three", value=3) 65 >>> cc3.save_base() 66 True 67 >>> cc3.name = u"THREE" 68 >>> cc3.save_base() 69 False 70 >>> cc3.name = u"Thr33" 71 >>> cc3.save_base(force_update=True) 72 False 73 >>> cc4 = Counter(name=u"four", value=4) 74 >>> cc4.save_base(force_insert=True) 75 True 63 76 """ 64 77 } -
tests/modeltests/proxy_models/models.py
171 171 [<OtherPerson: barney>, <OtherPerson: fred>] 172 172 >>> OtherPerson._default_manager.all() 173 173 [<OtherPerson: barney>, <OtherPerson: wilma>] 174 175 176 # Test save signals for proxy models 177 >>> from django.db.models import signals 178 >>> def foo(*args, **kwargs): print u"Foo" 179 ... 180 >>> def bar(*args, **kwargs): print u"Bar" 181 ... 182 >>> signals.pre_save.connect(foo, sender=MyPerson) 183 >>> signals.post_save.connect(bar, sender=MyPerson) 184 >>> dino = MyPerson.objects.create(name=u"dino") 185 Foo 186 Bar 174 187 """} 175 188 176 189 -
tests/modeltests/signals/models.py
63 63 post_save signal, Tom Smith 64 64 Is updated 65 65 Is raw 66 False 66 67 67 68 >>> p1.delete() 68 69 pre_delete signal, Tom Smith -
tests/regressiontests/model_inheritance_regress/models.py
121 121 # Create a child-parent-grandparent chain 122 122 >>> place1 = Place(name="Guido's House of Pasta", address='944 W. Fullerton') 123 123 >>> place1.save_base(raw=True) 124 True 124 125 >>> restaurant = Restaurant(place_ptr=place1, serves_hot_dogs=True, serves_pizza=False) 125 126 >>> restaurant.save_base(raw=True) 127 True 126 128 >>> italian_restaurant = ItalianRestaurant(restaurant_ptr=restaurant, serves_gnocchi=True) 127 129 >>> italian_restaurant.save_base(raw=True) 130 True 128 131 129 132 # Create a child-parent chain with an explicit parent link 130 133 >>> place2 = Place(name='Main St', address='111 Main St') 131 134 >>> place2.save_base(raw=True) 135 True 132 136 >>> park = ParkingLot(parent=place2, capacity=100) 133 137 >>> park.save_base(raw=True) 138 True 134 139 135 140 # Check that no extra parent objects have been created. 136 141 >>> Place.objects.all() … … 148 153 >>> [sorted(d.items()) for d in dicts] 149 154 [[('capacity', 100), ('name', u'Main St')]] 150 155 151 # You can also update objects when using a raw save .156 # You can also update objects when using a raw save, in which case False is returned. 152 157 >>> place1.name = "Guido's All New House of Pasta" 153 158 >>> place1.save_base(raw=True) 159 False 154 160 155 161 >>> restaurant.serves_hot_dogs = False 156 162 >>> restaurant.save_base(raw=True) 163 False 157 164 158 165 >>> italian_restaurant.serves_gnocchi = False 159 166 >>> italian_restaurant.save_base(raw=True) 167 False 160 168 161 169 >>> place2.name='Derelict lot' 162 170 >>> place2.save_base(raw=True) 171 False 163 172 164 173 >>> park.capacity = 50 165 174 >>> park.save_base(raw=True) 175 False 166 176 167 177 # No extra parent objects after an update, either. 168 178 >>> Place.objects.all() … … 185 195 186 196 >>> italian_restaurant.name = "Lorenzo's Pasta Hut" 187 197 >>> italian_restaurant.save_base(raw=True) 198 False 188 199 189 200 # Note that the name has not changed 190 201 # - name is an attribute of Place, not ItalianRestaurant