From a3b22d9db07ab21bda752f765b0a4414c73dee57 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 15 Oct 2007 03:32:11 +0000 Subject: queryset-refactor: Added ~ support to Q-objects. Based heavily on a patch from Collin Grady. Refs #4858. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6518 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/or_lookups/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/modeltests/or_lookups/models.py b/tests/modeltests/or_lookups/models.py index 5dc8351054..b3500f27e7 100644 --- a/tests/modeltests/or_lookups/models.py +++ b/tests/modeltests/or_lookups/models.py @@ -90,6 +90,17 @@ __test__ = {'API_TESTS':""" >>> Article.objects.filter(Q(headline__contains='bye'), headline__startswith='Hello') [] +# Q objects can be negated +>>> Article.objects.filter(Q(pk=1) | ~Q(pk=2)) +[, ] +>>> Article.objects.filter(~Q(pk=1) & ~Q(pk=2)) +[] + +# This allows for more complex queries than filter() and exclude() alone would +# allow +>>> Article.objects.filter(Q(pk=1) & (~Q(pk=2) | Q(pk=3))) +[] + # Try some arg queries with operations other than get_list >>> Article.objects.get(Q(headline__startswith='Hello'), Q(headline__contains='bye')) -- cgit v1.3