Code

Ticket #2473: tests.diff

File tests.diff, 1.0 KB (added by Gary Wilson <gary.wilson@…>, 8 years ago)

added some tests

Line 
1=== modified file 'tests/modeltests/or_lookups/models.py'
2--- tests/modeltests/or_lookups/models.py       2006-12-19 04:35:09 +0000
3+++ tests/modeltests/or_lookups/models.py       2006-12-19 06:49:47 +0000
4@@ -69,6 +69,21 @@
5 >>> Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3))
6 [<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
7 
8+# You could also use "in" to accomplish the same as above.
9+>>> Article.objects.filter(pk__in=[1,2,3])
10+[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
11+
12+>>> Article.objects.filter(pk__in=[1,2,3,4])
13+[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
14+
15+# Passing "in" an empty list returns no results.
16+>>> Article.objects.filter(pk__in=[])
17+[]
18+
19+# But can return results if we OR it with another query.
20+>>> Article.objects.filter(Q(pk__in=[]) | Q(headline__icontains='goodbye'))
21+[<Article: Goodbye>, <Article: Hello and goodbye>]
22+
23 # Q arg objects are ANDed
24 >>> Article.objects.filter(Q(headline__startswith='Hello'), Q(headline__contains='bye'))
25 [<Article: Hello and goodbye>]
26