Ticket #10672: 10672.2.diff
File 10672.2.diff, 3.8 KB (added by , 15 years ago) |
---|
-
django/db/models/base.py
420 420 ('raw' and 'cls'). 421 421 """ 422 422 assert not (force_insert and force_update) 423 if not cls: 424 cls = self.__class__ 423 klass = cls 424 if not klass: 425 klass = self.__class__ 425 426 meta = self._meta 426 427 signal = True 427 428 signals.pre_save.send(sender=self.__class__, instance=self, raw=raw) 428 429 else: 429 meta = cls._meta430 meta = klass._meta 430 431 signal = False 431 432 432 433 # If we are in a raw save, save the object exactly as presented. … … 441 442 if field and getattr(self, parent._meta.pk.attname) is None and getattr(self, field.attname) is not None: 442 443 setattr(self, parent._meta.pk.attname, getattr(self, field.attname)) 443 444 444 self.save_base(cls=parent)445 record_exists = not self.save_base(cls=parent) 445 446 if field: 446 447 setattr(self, field.attname, self._get_pk_val(parent._meta)) 447 if meta.proxy:448 return449 448 450 449 if not meta.proxy: 451 450 non_pks = [f for f in meta.local_fields if not f.primary_key] … … 454 453 pk_val = self._get_pk_val(meta) 455 454 pk_set = pk_val is not None 456 455 record_exists = True 457 manager = cls._base_manager456 manager = klass._base_manager 458 457 if pk_set: 459 458 # Determine whether a record with the primary key already exists. 460 459 if (force_update or (not force_insert and … … 496 495 signals.post_save.send(sender=self.__class__, instance=self, 497 496 created=(not record_exists), raw=raw) 498 497 498 if cls: 499 return (not record_exists) 500 499 501 save_base.alters_data = True 500 502 501 503 def _collect_sub_objects(self, seen_objs, parent=None, nullable=False): -
tests/modeltests/proxy_models/models.py
259 259 >>> OtherPerson._default_manager.all() 260 260 [<OtherPerson: barney>, <OtherPerson: wilma>] 261 261 262 # Test save signals for proxy models 263 >>> from django.db.models import signals 264 >>> def proxy_pre_save(*args, **kwargs): print u"proxy pre save" 265 ... 266 >>> def proxy_post_save(*args, **kwargs): print u"proxy post save" 267 ... 268 >>> signals.pre_save.connect(proxy_pre_save, sender=MyPerson) 269 >>> signals.post_save.connect(proxy_post_save, sender=MyPerson) 270 >>> dino = MyPerson.objects.create(name=u"dino") 271 proxy pre save 272 proxy post save 273 274 # And test save signals for proxy proxy models 275 >>> from django.db.models import signals 276 >>> def proxy_proxy_pre_save(*args, **kwargs): print u"proxy proxy pre save" 277 ... 278 >>> def proxy_proxy_post_save(*args, **kwargs): print u"proxy proxy post save" 279 ... 280 >>> signals.pre_save.connect(proxy_proxy_pre_save, sender=MyPersonProxy) 281 >>> signals.post_save.connect(proxy_proxy_post_save, sender=MyPersonProxy) 282 >>> dino = MyPersonProxy.objects.create(name=u"pebbles") 283 proxy proxy pre save 284 proxy proxy post save 285 262 286 # A proxy has the same content type as the model it is proxying for (at the 263 287 # storage level, it is meant to be essentially indistinguishable). 264 288 >>> ctype = ContentType.objects.get_for_model … … 266 290 True 267 291 268 292 >>> MyPersonProxy.objects.all() 269 [<MyPersonProxy: barney>, <MyPersonProxy: fred>]293 [<MyPersonProxy: barney>, <MyPersonProxy: dino>, <MyPersonProxy: fred>, <MyPersonProxy: pebbles>] 270 294 271 295 >>> u = User.objects.create(name='Bruce') 272 296 >>> User.objects.all()