summaryrefslogtreecommitdiff
path: root/django/db/models/base.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-06-08 13:04:22 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-06-08 13:04:22 +0000
commit81aedbd157209518a2a25ac528f29893900c1ae5 (patch)
tree10e9f4233b99ef8579b26a3d09cba0104e729dc6 /django/db/models/base.py
parent6cd37e0a1ffff06517a62c1cb0009825c551e31c (diff)
Fixed #10672 -- Altered save_base to ensure that proxy models send a post_save signal.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10954 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/base.py')
-rw-r--r--django/db/models/base.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 13ff7e8f35..325e8764f1 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -411,29 +411,35 @@ class Model(object):
save.alters_data = True
- def save_base(self, raw=False, cls=None, force_insert=False,
- force_update=False):
+ def save_base(self, raw=False, cls=None, origin=None,
+ force_insert=False, force_update=False):
"""
Does the heavy-lifting involved in saving. Subclasses shouldn't need to
override this method. It's separate from save() in order to hide the
need for overrides of save() to pass around internal-only parameters
- ('raw' and 'cls').
+ ('raw', 'cls', and 'origin').
"""
assert not (force_insert and force_update)
- if not cls:
+ if cls is None:
cls = self.__class__
- meta = self._meta
- signal = True
- signals.pre_save.send(sender=self.__class__, instance=self, raw=raw)
+ meta = cls._meta
+ if not meta.proxy:
+ origin = cls
else:
meta = cls._meta
- signal = False
+
+ if origin:
+ signals.pre_save.send(sender=origin, instance=self, raw=raw)
# If we are in a raw save, save the object exactly as presented.
# That means that we don't try to be smart about saving attributes
# that might have come from the parent class - we just save the
# attributes we have been given to the class we have been given.
if not raw:
+ if meta.proxy:
+ org = cls
+ else:
+ org = None
for parent, field in meta.parents.items():
# At this point, parent's primary key field may be unknown
# (for example, from administration form which doesn't fill
@@ -441,7 +447,8 @@ class Model(object):
if field and getattr(self, parent._meta.pk.attname) is None and getattr(self, field.attname) is not None:
setattr(self, parent._meta.pk.attname, getattr(self, field.attname))
- self.save_base(cls=parent)
+ self.save_base(cls=parent, origin=org)
+
if field:
setattr(self, field.attname, self._get_pk_val(parent._meta))
if meta.proxy:
@@ -492,8 +499,8 @@ class Model(object):
setattr(self, meta.pk.attname, result)
transaction.commit_unless_managed()
- if signal:
- signals.post_save.send(sender=self.__class__, instance=self,
+ if origin:
+ signals.post_save.send(sender=origin, instance=self,
created=(not record_exists), raw=raw)
save_base.alters_data = True