Code

Ticket #19837: 19837-test.diff

File 19837-test.diff, 1.9 KB (added by timo, 17 months ago)
Line 
1diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
2index 16583e8..7f0eb63 100644
3--- a/tests/regressiontests/queries/models.py
4+++ b/tests/regressiontests/queries/models.py
5@@ -439,3 +439,16 @@ class BaseA(models.Model):
6     a = models.ForeignKey(FK1, null=True)
7     b = models.ForeignKey(FK2, null=True)
8     c = models.ForeignKey(FK3, null=True)
9+
10+class Identifier(models.Model):
11+    name = models.TextField()
12+
13+    def __unicode__(self):
14+        return self.name
15+
16+class Program(models.Model):
17+    identifier = models.OneToOneField(Identifier)
18+
19+class Channel(models.Model):
20+    programs = models.ManyToManyField(Program)
21+    identifier = models.OneToOneField(Identifier)
22diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
23index ea54d18..4d688eb 100644
24--- a/tests/regressiontests/queries/tests.py
25+++ b/tests/regressiontests/queries/tests.py
26@@ -2612,3 +2612,19 @@ class DisjunctionPromotionTests(TestCase):
27         qs = BaseA.objects.filter(Q(a__f1=F('c__f1')) | (Q(pk=1) & Q(pk=2)))
28         self.assertEqual(str(qs.query).count('LEFT OUTER JOIN'), 2)
29         self.assertEqual(str(qs.query).count('INNER JOIN'), 0)
30+
31+from .models import Identifier,Program, Channel
32+
33+class ManyToManyExcludeTest(TestCase):
34+    def test_exclude_many_to_many(self):
35+        Identifier.objects.create(name='extra')
36+        program = Program.objects.create(identifier=Identifier.objects.create(name='program'))
37+        channel = Channel.objects.create(identifier=Identifier.objects.create(name='channel'))
38+        channel.programs.add(program)
39+
40+        # channel contains 'program1', so all Identifiers except that one
41+        # should be returned
42+        self.assertQuerysetEqual(
43+            Identifier.objects.exclude(program__channel=channel).order_by('name'),
44+            ['<Identifier: channel>', '<Identifier: extra>']
45+        )