summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2011-01-11 01:03:08 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2011-01-11 01:03:08 +0000
commitb28756bb29a4fec78896791ad12775a339ce3651 (patch)
tree867c9c6cc4269d2e5524d89414814ae3c27d2547 /tests
parent52999afaf5b6960837e64bf59d83cb856d1c6a3e (diff)
[1.2.X] Fixed #11293 -- fixed using Q objects to generate ORs with aggregates. Backport of [15173].
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15174 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/aggregation_regress/tests.py55
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py
index 4d5a2a0ab5..16944af094 100644
--- a/tests/regressiontests/aggregation_regress/tests.py
+++ b/tests/regressiontests/aggregation_regress/tests.py
@@ -6,7 +6,7 @@ from operator import attrgetter
from django.conf import settings
from django.core.exceptions import FieldError
from django.db import DEFAULT_DB_ALIAS
-from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F
+from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F, Q
from django.test import TestCase, Approximate
from models import Author, Book, Publisher, Clues, Entries, HardbackBook
@@ -694,6 +694,59 @@ class AggregationTests(TestCase):
list(qs), list(Book.objects.values_list("name", flat=True))
)
+ def test_annotation_disjunction(self):
+ qs = Book.objects.annotate(n_authors=Count("authors")).filter(
+ Q(n_authors=2) | Q(name="Python Web Development with Django")
+ )
+ self.assertQuerysetEqual(
+ qs, [
+ "Artificial Intelligence: A Modern Approach",
+ "Python Web Development with Django",
+ "The Definitive Guide to Django: Web Development Done Right",
+ ],
+ attrgetter("name")
+ )
+
+ qs = Book.objects.annotate(n_authors=Count("authors")).filter(
+ Q(name="The Definitive Guide to Django: Web Development Done Right") | (Q(name="Artificial Intelligence: A Modern Approach") & Q(n_authors=3))
+ )
+ self.assertQuerysetEqual(
+ qs, [
+ "The Definitive Guide to Django: Web Development Done Right",
+ ],
+ attrgetter("name")
+ )
+
+ qs = Publisher.objects.annotate(
+ rating_sum=Sum("book__rating"),
+ book_count=Count("book")
+ ).filter(
+ Q(rating_sum__gt=5.5) | Q(rating_sum__isnull=True)
+ ).order_by('pk')
+ self.assertQuerysetEqual(
+ qs, [
+ "Apress",
+ "Prentice Hall",
+ "Jonno's House of Books",
+ ],
+ attrgetter("name")
+ )
+
+ qs = Publisher.objects.annotate(
+ rating_sum=Sum("book__rating"),
+ book_count=Count("book")
+ ).filter(
+ Q(pk__lt=F("book_count")) | Q(rating_sum=None)
+ ).order_by("pk")
+ self.assertQuerysetEqual(
+ qs, [
+ "Apress",
+ "Jonno's House of Books",
+ ],
+ attrgetter("name")
+ )
+
+
if run_stddev_tests():
def test_stddev(self):
self.assertEqual(