1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #27407 -- Made Model.delete(keep_parents=True) preserve parent reverse relationships.

Thanks Tim for the review.
This commit is contained in:
Simon Charette
2016-09-10 20:30:14 -04:00
parent eed6150009
commit 31a56e30cf
3 changed files with 16 additions and 0 deletions

View File

@@ -206,7 +206,11 @@ class Collector(object):
collect_related=False,
reverse_dependency=True)
if collect_related:
parents = model._meta.parents
for related in get_candidate_relations_to_delete(model._meta):
# Preserve parent reverse relationships if keep_parents=True.
if keep_parents and related.model in parents:
continue
field = related.field
if field.remote_field.on_delete == DO_NOTHING:
continue