summaryrefslogtreecommitdiff
path: root/django/db/models/base.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-20 03:57:12 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-20 03:57:12 +0000
commitfa89fdcd6b4a4ab4887740c0d0f4a73297a5b060 (patch)
treed32b42ab5121a4014b420e70f86c26c4d2222457 /django/db/models/base.py
parent44b0f68f44c4e5ca6f2b9da294dab1db531abc6e (diff)
Fixed #2698 -- Fixed deleting in the presence of custom managers.
A custom manager on a related object that filtered away objects would prevent those objects being deleted via the relation. This is now fixed. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10104 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/base.py')
-rw-r--r--django/db/models/base.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index cf5903d289..013dc96e92 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -519,7 +519,17 @@ class Model(object):
else:
sub_obj._collect_sub_objects(seen_objs, self.__class__, related.field.null)
else:
- for sub_obj in getattr(self, rel_opts_name).all():
+ # To make sure we can access all elements, we can't use the
+ # normal manager on the related object. So we work directly
+ # with the descriptor object.
+ for cls in self.__class__.mro():
+ if rel_opts_name in cls.__dict__:
+ rel_descriptor = cls.__dict__[rel_opts_name]
+ break
+ else:
+ raise AssertionError("Should never get here.")
+ delete_qs = rel_descriptor.delete_manager(self).all()
+ for sub_obj in delete_qs:
sub_obj._collect_sub_objects(seen_objs, self.__class__, related.field.null)
# Handle any ancestors (for the model-inheritance case). We do this by