Last active
August 29, 2015 14:00
-
-
Save loic/11062674 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/django/db/models/base.py b/django/db/models/base.py | |
index a0f43de..d481e13 100644 | |
--- a/django/db/models/base.py | |
+++ b/django/db/models/base.py | |
@@ -648,23 +648,25 @@ class Model(six.with_metaclass(ModelBase)): | |
""" | |
meta = cls._meta | |
for parent, field in meta.parents.items(): | |
+ self._save_parents(cls=parent, using=using, update_fields=update_fields) | |
+ | |
# Make sure the link fields are synced between parent and self. | |
- if (field and getattr(self, parent._meta.pk.attname) is None | |
- and getattr(self, field.attname) is not None): | |
+ if getattr(self, field.attname) is not None: | |
setattr(self, parent._meta.pk.attname, getattr(self, field.attname)) | |
- self._save_parents(cls=parent, using=using, update_fields=update_fields) | |
+ | |
self._save_table(cls=parent, using=using, update_fields=update_fields) | |
+ | |
# Set the parent's PK value to self. | |
- if field: | |
- setattr(self, field.attname, self._get_pk_val(parent._meta)) | |
- # Since we didn't have an instance of the parent handy set | |
- # attname directly, bypassing the descriptor. Invalidate | |
- # the related object cache, in case it's been accidentally | |
- # populated. A fresh instance will be re-built from the | |
- # database if necessary. | |
- cache_name = field.get_cache_name() | |
- if hasattr(self, cache_name): | |
- delattr(self, cache_name) | |
+ setattr(self, field.attname, self._get_pk_val(parent._meta)) | |
+ | |
+ # Since we didn't have an instance of the parent handy set | |
+ # attname directly, bypassing the descriptor. Invalidate | |
+ # the related object cache, in case it's been accidentally | |
+ # populated. A fresh instance will be re-built from the | |
+ # database if necessary. | |
+ cache_name = field.get_cache_name() | |
+ if hasattr(self, cache_name): | |
+ delattr(self, cache_name) | |
def _save_table(self, raw=False, cls=None, force_insert=False, | |
force_update=False, using=None, update_fields=None): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment