summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChris Lamb <chris@chris-lamb.co.uk>2016-08-17 21:09:50 +0100
committerTim Graham <timograham@gmail.com>2016-08-17 21:19:22 -0400
commitc24a47b3e6cfba88ee7792be25da5b5333266abe (patch)
treec81cf8b2e1634cddfafe895c3a3c6f78f291cbd9 /tests
parent04f0c2ab39396a5b3002d7fe3e2b0648c63ac3cc (diff)
[1.10.x] Refs #26983 -- Added test for isnull lookup to CharField with primary_key=True.
Backport of 97513269d73520d10722bbd10404be6ac4d48d07 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/queries/models.py2
-rw-r--r--tests/queries/tests.py11
2 files changed, 11 insertions, 2 deletions
diff --git a/tests/queries/models.py b/tests/queries/models.py
index 523b58c7e4..c0ce3a5d60 100644
--- a/tests/queries/models.py
+++ b/tests/queries/models.py
@@ -261,7 +261,7 @@ class CustomPk(models.Model):
class Related(models.Model):
- custom = models.ForeignKey(CustomPk, models.CASCADE)
+ custom = models.ForeignKey(CustomPk, models.CASCADE, null=True)
class CustomPkTag(models.Model):
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index a3a810ce5e..46a147c9d8 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -2483,7 +2483,16 @@ class ToFieldTests(TestCase):
[node1]
)
- def test_isnull_query(self):
+
+class IsNullTests(TestCase):
+ def test_primary_key(self):
+ custom = CustomPk.objects.create(name='pk')
+ null = Related.objects.create()
+ notnull = Related.objects.create(custom=custom)
+ self.assertSequenceEqual(Related.objects.filter(custom__isnull=False), [notnull])
+ self.assertSequenceEqual(Related.objects.filter(custom__isnull=True), [null])
+
+ def test_to_field(self):
apple = Food.objects.create(name="apple")
Eaten.objects.create(food=apple, meal="lunch")
Eaten.objects.create(meal="lunch")