summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2014-01-28 21:36:57 +0200
committerAnssi Kääriäinen <akaariai@gmail.com>2014-01-28 21:39:15 +0200
commit8b2c1ac06d3d1cf99661f4af75030abb456e1665 (patch)
treeabace994d07f824c92fba9eea8b4b68bf0df94fa
parent0ca647357ecb0e3fe507d90a9518198751b2d408 (diff)
Added tests for m2m queries with custom pk on the end models
It seems this case was fixed somewhere between 1.5.x and 1.6.x. I added tests as I wasn't able to find any tests for these cases. Refs #21879
-rw-r--r--tests/queries/models.py6
-rw-r--r--tests/queries/tests.py15
2 files changed, 20 insertions, 1 deletions
diff --git a/tests/queries/models.py b/tests/queries/models.py
index cc952e8bfc..b38f672ea6 100644
--- a/tests/queries/models.py
+++ b/tests/queries/models.py
@@ -258,6 +258,12 @@ class CustomPk(models.Model):
class Related(models.Model):
custom = models.ForeignKey(CustomPk)
+
+class CustomPkTag(models.Model):
+ id = models.CharField(max_length=20, primary_key=True)
+ custom_pk = models.ManyToManyField(CustomPk)
+ tag = models.CharField(max_length=20)
+
# An inter-related setup with a model subclass that has a nullable
# path to another model, and a return path from that model.
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index b303d5f603..6bf90cdbf9 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -27,7 +27,7 @@ from .models import (
BaseA, FK1, Identifier, Program, Channel, Page, Paragraph, Chapter, Book,
MyObject, Order, OrderItem, SharedConnection, Task, Staff, StaffUser,
CategoryRelationship, Ticket21203Parent, Ticket21203Child, Person,
- Company, Employment)
+ Company, Employment, CustomPk, CustomPkTag)
class BaseQuerysetTest(TestCase):
@@ -3243,3 +3243,16 @@ class ForeignKeyToBaseExcludeTests(TestCase):
SpecialCategory.objects.filter(categoryitem__id=c1.pk),
[sc1], lambda x: x
)
+
+
+class ReverseM2MCustomPkTests(TestCase):
+ def test_ticket_21879(self):
+ cpt1 = CustomPkTag.objects.create(id='cpt1', tag='cpt1')
+ cp1 = CustomPk.objects.create(name='cp1', extra='extra')
+ cp1.custompktag_set.add(cpt1)
+ self.assertQuerysetEqual(
+ CustomPk.objects.filter(custompktag=cpt1), [cp1],
+ lambda x: x)
+ self.assertQuerysetEqual(
+ CustomPkTag.objects.filter(custom_pk=cp1), [cpt1],
+ lambda x: x)