diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2006-05-16 20:39:14 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2006-05-16 20:39:14 +0000 |
| commit | e1184016a29b90694e3624d646b35b9d4aa4756e (patch) | |
| tree | f15b0c5f1ccd0f22b132b97403304263da579fb9 /tests | |
| parent | 93937ed38a828e0f252fb25614516593ec7b9ab0 (diff) | |
multi-auth: Merged to [2919]
git-svn-id: http://code.djangoproject.com/svn/django/branches/multi-auth@2921 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/basic/models.py | 2 | ||||
| -rw-r--r-- | tests/modeltests/many_to_many/models.py | 7 | ||||
| -rw-r--r-- | tests/modeltests/many_to_one/models.py | 6 | ||||
| -rw-r--r-- | tests/modeltests/many_to_one_null/models.py | 2 | ||||
| -rw-r--r-- | tests/modeltests/or_lookups/models.py | 7 |
5 files changed, 20 insertions, 4 deletions
diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index 16df447c91..0470d6bc9b 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -197,7 +197,7 @@ TypeError: dates() takes at least 3 arguments (1 given) >>> Article.objects.dates('invalid_field', 'year') Traceback (most recent call last): ... -FieldDoesNotExist: name=invalid_field +FieldDoesNotExist: Article has no field named 'invalid_field' >>> Article.objects.dates('pub_date', 'bad_kind') Traceback (most recent call last): diff --git a/tests/modeltests/many_to_many/models.py b/tests/modeltests/many_to_many/models.py index 35677d1524..4422cb1a6a 100644 --- a/tests/modeltests/many_to_many/models.py +++ b/tests/modeltests/many_to_many/models.py @@ -82,6 +82,13 @@ API_TESTS = """ >>> Article.objects.filter(publications__title__startswith="Science").distinct() [NASA uses Python] +# The count() function respects distinct() as well. +>>> Article.objects.filter(publications__title__startswith="Science").count() +2 + +>>> Article.objects.filter(publications__title__startswith="Science").distinct().count() +1 + # Reverse m2m queries are supported (i.e., starting at the table that doesn't # have a ManyToManyField). >>> Publication.objects.filter(id__exact=1) diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py index 165a36c91c..3a0972b793 100644 --- a/tests/modeltests/many_to_one/models.py +++ b/tests/modeltests/many_to_one/models.py @@ -205,6 +205,12 @@ John Smith >>> Reporter.objects.filter(article__headline__startswith='This').distinct() [John Smith] +# Counting in the opposite direction works in conjunction with distinct() +>>> Reporter.objects.filter(article__headline__startswith='This').count() +3 +>>> Reporter.objects.filter(article__headline__startswith='This').distinct().count() +1 + # Queries can go round in circles. >>> Reporter.objects.filter(article__reporter__first_name__startswith='John') [John Smith, John Smith, John Smith, John Smith] diff --git a/tests/modeltests/many_to_one_null/models.py b/tests/modeltests/many_to_one_null/models.py index 6818493ee3..638382107a 100644 --- a/tests/modeltests/many_to_one_null/models.py +++ b/tests/modeltests/many_to_one_null/models.py @@ -103,7 +103,7 @@ None >>> r.article_set.remove(a4) Traceback (most recent call last): ... -DoesNotExist: 'Fourth' is not related to 'John Smith'. +DoesNotExist: 'Article object' is not related to 'Reporter object'. >>> r2.article_set.all() [Fourth] diff --git a/tests/modeltests/or_lookups/models.py b/tests/modeltests/or_lookups/models.py index cd01447a35..a07dacdd5a 100644 --- a/tests/modeltests/or_lookups/models.py +++ b/tests/modeltests/or_lookups/models.py @@ -44,10 +44,13 @@ API_TESTS = """ >>> Article.objects.filter(Q(headline__startswith='Hello') & Q(headline__startswith='Goodbye')) [] ->>> Article.objects.filter(headline__startswith='Hello') & Article.objects.filter(headline__startswith='Goodbye') +# You can shorten this syntax with code like the following, +# which is especially useful if building the query in stages: +>>> articles = Article.objects.all() +>>> articles.filter(headline__startswith='Hello') & articles.filter(headline__startswith='Goodbye') [] ->>> Article.objects.filter(headline__startswith='Hello') & Article.objects.filter(headline__contains='bye') +>>> articles.filter(headline__startswith='Hello') & articles.filter(headline__contains='bye') [Hello and goodbye] >>> Article.objects.filter(Q(headline__contains='bye'), headline__startswith='Hello') |
