Added a test for negated Q object querying

The added test is from the patch in ticket #19672 (written by Ian
Kelly). Fixed #19672, refs #19849.
This commit is contained in:
Anssi Kääriäinen 2013-02-20 21:09:27 +02:00
parent 10f9ba046f
commit e8fc3f3783
2 changed files with 10 additions and 2 deletions

View File

@ -64,6 +64,7 @@ class Annotation(models.Model):
class ExtraInfo(models.Model):
info = models.CharField(max_length=100)
note = models.ForeignKey(Note)
value = models.IntegerField(null=True)
class Meta:
ordering = ['info']

View File

@ -52,8 +52,8 @@ class Queries1Tests(BaseQuerysetTest):
# Create these out of order so that sorting by 'id' will be different to sorting
# by 'info'. Helps detect some problems later.
self.e2 = ExtraInfo.objects.create(info='e2', note=n2)
e1 = ExtraInfo.objects.create(info='e1', note=self.n1)
self.e2 = ExtraInfo.objects.create(info='e2', note=n2, value=41)
e1 = ExtraInfo.objects.create(info='e1', note=self.n1, value=42)
self.a1 = Author.objects.create(name='a1', num=1001, extra=e1)
self.a2 = Author.objects.create(name='a2', num=2002, extra=e1)
@ -1106,6 +1106,13 @@ class Queries1Tests(BaseQuerysetTest):
self.assertTrue(str(q3.query).count('LEFT OUTER JOIN') == 1)
self.assertTrue(str(q3.query).count('INNER JOIN') == 0)
def test_ticket19672(self):
self.assertQuerysetEqual(
Report.objects.filter(Q(creator__isnull=False) &
~Q(creator__extra__value=41)),
['<Report: r1>']
)
class Queries2Tests(TestCase):
def setUp(self):