summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-04-03 19:56:30 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-04-03 19:56:30 +0000
commit9907495b3c412ece76f5e5e4c4e5df12b93caf78 (patch)
tree857060089af27bc4af3c3b2cab807fa37a1fc513 /tests
parent597102199e70d88e9233023f13629194291aed43 (diff)
[1.0.X] Fixed #9546: GenericRelations inherited from base models no longer query using the wrong content type. Backport of r10373 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10374 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/generic_relations_regress/__init__.py0
-rw-r--r--tests/regressiontests/generic_relations_regress/models.py22
-rw-r--r--tests/regressiontests/generic_relations_regress/tests.py19
3 files changed, 41 insertions, 0 deletions
diff --git a/tests/regressiontests/generic_relations_regress/__init__.py b/tests/regressiontests/generic_relations_regress/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/generic_relations_regress/__init__.py
diff --git a/tests/regressiontests/generic_relations_regress/models.py b/tests/regressiontests/generic_relations_regress/models.py
new file mode 100644
index 0000000000..1a4826aaed
--- /dev/null
+++ b/tests/regressiontests/generic_relations_regress/models.py
@@ -0,0 +1,22 @@
+from django.db import models
+from django.contrib.contenttypes import generic
+from django.contrib.contenttypes.models import ContentType
+
+class Link(models.Model):
+ content_type = models.ForeignKey(ContentType)
+ object_id = models.PositiveIntegerField()
+ content_object = generic.GenericForeignKey()
+
+ def __unicode__(self):
+ return "Link to %s id=%s" % (self.content_type, self.object_id)
+
+class Place(models.Model):
+ name = models.CharField(max_length=100)
+ links = generic.GenericRelation(Link)
+
+ def __unicode__(self):
+ return "Place: %s" % self.name
+
+class Restaurant(Place):
+ def __unicode__(self):
+ return "Restaurant: %s" % self.name \ No newline at end of file
diff --git a/tests/regressiontests/generic_relations_regress/tests.py b/tests/regressiontests/generic_relations_regress/tests.py
new file mode 100644
index 0000000000..6f0863d7b4
--- /dev/null
+++ b/tests/regressiontests/generic_relations_regress/tests.py
@@ -0,0 +1,19 @@
+from django.test import TestCase
+from django.contrib.contenttypes.models import ContentType
+from models import Link, Place, Restaurant
+
+class GenericRelationTests(TestCase):
+
+ def test_inherited_models_content_type(self):
+ """
+ Test that GenericRelations on inherited classes use the correct content
+ type.
+ """
+
+ p = Place.objects.create(name="South Park")
+ r = Restaurant.objects.create(name="Chubby's")
+ l1 = Link.objects.create(content_object=p)
+ l2 = Link.objects.create(content_object=r)
+ self.assertEqual(list(p.links.all()), [l1])
+ self.assertEqual(list(r.links.all()), [l2])
+ \ No newline at end of file