From 2e24596001bce6e827e31510241834ccff76979f Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 19 May 2009 13:42:38 +0000 Subject: [PATCH] Fixed #11116 -- Corrected the deletion of proxy objects. Thanks to Samuel Adam for the fix. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10824 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/base.py | 2 +- tests/modeltests/proxy_models/models.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 3a3fbf16ac..13ff7e8f35 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -538,7 +538,7 @@ class Model(object): # traversing to the most remote parent classes -- those with no parents # themselves -- and then adding those instances to the collection. That # will include all the child instances down to "self". - parent_stack = self._meta.parents.values() + parent_stack = [p for p in self._meta.parents.values() if p is not None] while parent_stack: link = parent_stack.pop() parent_obj = getattr(self, link.name) diff --git a/tests/modeltests/proxy_models/models.py b/tests/modeltests/proxy_models/models.py index baa58cba03..4b3f7d925d 100644 --- a/tests/modeltests/proxy_models/models.py +++ b/tests/modeltests/proxy_models/models.py @@ -276,6 +276,15 @@ True >>> UserProxyProxy.objects.all() [] +# Proxy objects can be deleted +>>> u2 = UserProxy.objects.create(name='George') +>>> UserProxy.objects.all() +[, ] +>>> u2.delete() +>>> UserProxy.objects.all() +[] + + # We can still use `select_related()` to include related models in our querysets. >>> country = Country.objects.create(name='Australia') >>> state = State.objects.create(name='New South Wales', country=country)