diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-20 22:14:31 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-20 22:14:31 +0000 |
| commit | ebfe7faaa3efef952d092b332b79f182ea5f45d1 (patch) | |
| tree | 0fbcfac644241e7edbe515b56ab6bf5a3d4f01dc /django/db/models/base.py | |
| parent | 083a7206e471a8f67e7ba61b5b1085fd939547af (diff) | |
[1.0.X] 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.
Backport of r10104 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10106 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/base.py')
| -rw-r--r-- | django/db/models/base.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index dec0316947..34b31b89af 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -437,7 +437,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 |
