Ticket #10672: 10672.2.diff

File 10672.2.diff, 3.8 KB (added by Ulrich Petri, 15 years ago)

Updated to trunk (r10836)

  • django/db/models/base.py

     
    420420        ('raw' and 'cls').
    421421        """
    422422        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__
    425426            meta = self._meta
    426427            signal = True
    427428            signals.pre_save.send(sender=self.__class__, instance=self, raw=raw)
    428429        else:
    429             meta = cls._meta
     430            meta = klass._meta
    430431            signal = False
    431432
    432433        # If we are in a raw save, save the object exactly as presented.
     
    441442                if field and getattr(self, parent._meta.pk.attname) is None and getattr(self, field.attname) is not None:
    442443                    setattr(self, parent._meta.pk.attname, getattr(self, field.attname))
    443444
    444                 self.save_base(cls=parent)
     445                record_exists = not self.save_base(cls=parent)
    445446                if field:
    446447                    setattr(self, field.attname, self._get_pk_val(parent._meta))
    447             if meta.proxy:
    448                 return
    449448
    450449        if not meta.proxy:
    451450            non_pks = [f for f in meta.local_fields if not f.primary_key]
     
    454453            pk_val = self._get_pk_val(meta)
    455454            pk_set = pk_val is not None
    456455            record_exists = True
    457             manager = cls._base_manager
     456            manager = klass._base_manager
    458457            if pk_set:
    459458                # Determine whether a record with the primary key already exists.
    460459                if (force_update or (not force_insert and
     
    496495            signals.post_save.send(sender=self.__class__, instance=self,
    497496                created=(not record_exists), raw=raw)
    498497
     498        if cls:
     499            return (not record_exists)
     500
    499501    save_base.alters_data = True
    500502
    501503    def _collect_sub_objects(self, seen_objs, parent=None, nullable=False):
  • tests/modeltests/proxy_models/models.py

     
    259259>>> OtherPerson._default_manager.all()
    260260[<OtherPerson: barney>, <OtherPerson: wilma>]
    261261
     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")
     271proxy pre save
     272proxy 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")
     283proxy proxy pre save
     284proxy proxy post save
     285
    262286# A proxy has the same content type as the model it is proxying for (at the
    263287# storage level, it is meant to be essentially indistinguishable).
    264288>>> ctype = ContentType.objects.get_for_model
     
    266290True
    267291
    268292>>> MyPersonProxy.objects.all()
    269 [<MyPersonProxy: barney>, <MyPersonProxy: fred>]
     293[<MyPersonProxy: barney>, <MyPersonProxy: dino>, <MyPersonProxy: fred>, <MyPersonProxy: pebbles>]
    270294
    271295>>> u = User.objects.create(name='Bruce')
    272296>>> User.objects.all()
Back to Top