1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #29871 -- Allowed setting pk=None on a child model to create a copy.

Thanks Simon Charette and Tim Graham for the initial patch.
This commit is contained in:
chetan22
2019-10-28 10:58:40 +05:30
committed by Mariusz Felisiak
parent 927c903f3c
commit 63e6ee1f99
2 changed files with 36 additions and 4 deletions

View File

@@ -569,6 +569,9 @@ class Model(metaclass=ModelBase):
return getattr(self, meta.pk.attname)
def _set_pk_val(self, value):
for parent_link in self._meta.parents.values():
if parent_link and parent_link != self._meta.pk:
setattr(self, parent_link.target_field.attname, value)
return setattr(self, self._meta.pk.attname, value)
pk = property(_get_pk_val, _set_pk_val)