summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-05-14 23:49:29 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-05-14 23:49:29 +0000
commit1006d6eb06e202a5060d7346973a3dbc3bd0ec53 (patch)
tree0d7ed66a3dd335ce04c7102413441801816f0381 /tests
parentaa11b3ea503ba1e6247e1629aa13f2752f32e3a9 (diff)
Fixed #1530 -- make count() respect distinct() on QuerySets. Create some
tests for this as well. Thanks to Adam Endicott for the original patch on which this is based. git-svn-id: http://code.djangoproject.com/svn/django/trunk@2902 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/many_to_many/models.py7
-rw-r--r--tests/modeltests/many_to_one/models.py6
2 files changed, 13 insertions, 0 deletions
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]