Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: django/django
...
head fork: jaklaassen/django
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 08, 2012
@jaklaassen jaklaassen Fixed #11263
Fixed a bug where generic relations on concrete model base classes with
concrete subclasses did not use the correct content type ID for
filters on the subclass. Added a test for this and another related
reported issue that now works in trunk.
e7f0dee
View
1  django/contrib/contenttypes/generic.py
@@ -191,6 +191,7 @@ def contribute_to_class(self, cls, name):
# Save a reference to which model this class is on for future use
self.model = cls
+ cls._meta.add_virtual_field(self)
# Add the descriptor for the m2m relation
setattr(cls, self.name, ReverseGenericRelatedObjectsDescriptor(self))
View
6 tests/modeltests/generic_relations/models.py
@@ -88,3 +88,9 @@ def get_query_set(self):
class Gecko(models.Model):
has_tail = models.BooleanField()
objects = GeckoManager()
+
+class Mammal(Animal):
+ pass
+
+class Rock(Mineral):
+ tags = generic.GenericRelation(TaggedItem)
View
19 tests/modeltests/generic_relations/tests.py
@@ -6,7 +6,7 @@
from django.test import TestCase
from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal,
- Vegetable, Mineral, Gecko)
+ Vegetable, Mineral, Gecko, Rock, Mammal)
class GenericRelationsTests(TestCase):
@@ -197,6 +197,23 @@ def test_gfk_subclasses(self):
)
self.assertEqual(valuedtag.content_object, quartz)
+ def test_subclasses_with_gen_rel(self):
+ """Test that concrete model subclasses with generic relations work correctly
+ https://code.djangoproject.com/ticket/11263
+ """
+ granite = Rock.objects.create(name='granite', hardness=5)
+ tag = TaggedItem.objects.create(content_object=granite, tag="countertop")
+ self.assertEqual(Rock.objects.filter(tags__tag="countertop").count(), 1)
+
+ def test_subclasses_with_parent_gen_rel(self):
+ """Test that generic relations on a concrete model base class work correctly in subclasses
+ https://code.djangoproject.com/ticket/11263
+ """
+
+ bear = Mammal.objects.create(common_name='bear', latin_name='ursa')
+ tag = TaggedItem.objects.create(content_object=bear, tag="cuddly")
+ self.assertEqual(Mammal.objects.filter(tags__tag="cuddly").count(), 1)
+
def test_generic_inline_formsets(self):
GenericFormSet = generic_inlineformset_factory(TaggedItem, extra=1)
formset = GenericFormSet()

No commit comments for this range

Something went wrong with that request. Please try again.