From d95355b6db0a457130bce22bb1dbf1a48731dfc6 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 22 May 2011 15:21:03 +0000 Subject: Fixed #16048 -- Use the base manager instead of the default manager to retrieve a related object of a GenericForeignKey similar to ForeignKeys. Thanks, adurdin. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16261 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/generic_relations/models.py | 8 ++++++++ tests/modeltests/generic_relations/tests.py | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/modeltests/generic_relations/models.py b/tests/modeltests/generic_relations/models.py index 18b77a355e..f3e216edf5 100644 --- a/tests/modeltests/generic_relations/models.py +++ b/tests/modeltests/generic_relations/models.py @@ -78,3 +78,11 @@ class Mineral(models.Model): def __unicode__(self): return self.name + +class GeckoManager(models.Manager): + def get_query_set(self): + return super(GeckoManager, self).get_query_set().filter(has_tail=True) + +class Gecko(models.Model): + has_tail = models.BooleanField() + objects = GeckoManager() diff --git a/tests/modeltests/generic_relations/tests.py b/tests/modeltests/generic_relations/tests.py index a2bf3bedf6..7596f77fbe 100644 --- a/tests/modeltests/generic_relations/tests.py +++ b/tests/modeltests/generic_relations/tests.py @@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType from django.test import TestCase from models import (TaggedItem, ValuableTaggedItem, Comparison, Animal, - Vegetable, Mineral) + Vegetable, Mineral, Gecko) class GenericRelationsTests(TestCase): @@ -223,6 +223,11 @@ class GenericRelationsTests(TestCase): self.assertEqual(u''.join(form.as_p() for form in formset.forms), u"""

""") + def test_gfk_manager(self): + # GenericForeignKey should not use the default manager (which may filter objects) #16048 + tailless = Gecko.objects.create(has_tail=False) + tag = TaggedItem.objects.create(content_object=tailless, tag="lizard") + self.assertEqual(tag.content_object, tailless) class CustomWidget(forms.CharField): pass -- cgit v1.3