Ticket #2473: tests.diff

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

added some tests

  • tests/modeltests/or_lookups/models.py

    === modified file 'tests/modeltests/or_lookups/models.py'
    6969>>> Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3))
    7070[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
     72# You could also use "in" to accomplish the same as above.
     73>>> Article.objects.filter(pk__in=[1,2,3])
     74[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
     76>>> Article.objects.filter(pk__in=[1,2,3,4])
     77[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
     79# Passing "in" an empty list returns no results.
     80>>> Article.objects.filter(pk__in=[])
     83# But can return results if we OR it with another query.
     84>>> Article.objects.filter(Q(pk__in=[]) | Q(headline__icontains='goodbye'))
     85[<Article: Goodbye>, <Article: Hello and goodbye>]
    7287# Q arg objects are ANDed
    7388>>> Article.objects.filter(Q(headline__startswith='Hello'), Q(headline__contains='bye'))
    7489[<Article: Hello and goodbye>]
Back to Top