Skip to content

Commit

Permalink
Fixed #11116 -- Corrected the deletion of proxy objects. Thanks to Sa…
Browse files Browse the repository at this point in the history
…muel Adam for the fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10824 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed May 19, 2009
1 parent b9b9ca3 commit 2e24596
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/db/models/base.py
Expand Up @@ -538,7 +538,7 @@ def _collect_sub_objects(self, seen_objs, parent=None, nullable=False):
# traversing to the most remote parent classes -- those with no parents # traversing to the most remote parent classes -- those with no parents
# themselves -- and then adding those instances to the collection. That # themselves -- and then adding those instances to the collection. That
# will include all the child instances down to "self". # 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: while parent_stack:
link = parent_stack.pop() link = parent_stack.pop()
parent_obj = getattr(self, link.name) parent_obj = getattr(self, link.name)
Expand Down
9 changes: 9 additions & 0 deletions tests/modeltests/proxy_models/models.py
Expand Up @@ -276,6 +276,15 @@ class Meta:
>>> UserProxyProxy.objects.all() >>> UserProxyProxy.objects.all()
[<UserProxyProxy: Bruce>] [<UserProxyProxy: Bruce>]
# Proxy objects can be deleted
>>> u2 = UserProxy.objects.create(name='George')
>>> UserProxy.objects.all()
[<UserProxy: Bruce>, <UserProxy: George>]
>>> u2.delete()
>>> UserProxy.objects.all()
[<UserProxy: Bruce>]
# We can still use `select_related()` to include related models in our querysets. # We can still use `select_related()` to include related models in our querysets.
>>> country = Country.objects.create(name='Australia') >>> country = Country.objects.create(name='Australia')
>>> state = State.objects.create(name='New South Wales', country=country) >>> state = State.objects.create(name='New South Wales', country=country)
Expand Down

0 comments on commit 2e24596

Please sign in to comment.