Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #16048 -- Use the base manager instead of the default manager t…

…o retrieve a related object of a GenericForeignKey similar to ForeignKeys. Thanks, adurdin.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d95355b6db0a457130bce22bb1dbf1a48731dfc6 1 parent fc8116c
@jezdez jezdez authored
2  django/contrib/contenttypes/
@@ -100,7 +100,7 @@ def get_object_for_this_type(self, **kwargs):
method. The ObjectNotExist exception, if thrown, will not be caught,
so code that calls this method should catch it.
- return self.model_class()._default_manager.using(self._state.db).get(**kwargs)
+ return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
def natural_key(self):
return (self.app_label, self.model)
8 tests/modeltests/generic_relations/
@@ -78,3 +78,11 @@ class Mineral(models.Model):
def __unicode__(self):
+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()
7 tests/modeltests/generic_relations/
@@ -4,7 +4,7 @@
from django.test import TestCase
from models import (TaggedItem, ValuableTaggedItem, Comparison, Animal,
- Vegetable, Mineral)
+ Vegetable, Mineral, Gecko)
class GenericRelationsTests(TestCase):
@@ -223,6 +223,11 @@ def test_generic_inline_formsets(self):
self.assertEqual(u''.join(form.as_p() for form in formset.forms), u"""<p><label for="id_x-0-tag">Tag:</label> <input id="id_x-0-tag" type="text" name="x-0-tag" maxlength="50" /></p>
<p><label for="id_x-0-DELETE">Delete:</label> <input type="checkbox" name="x-0-DELETE" id="id_x-0-DELETE" /><input type="hidden" name="x-0-id" id="id_x-0-id" /></p>""")
+ 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):

0 comments on commit d95355b

Please sign in to comment.
Something went wrong with that request. Please try again.