diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2011-01-11 01:00:50 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2011-01-11 01:00:50 +0000 |
| commit | 29de7ee9cb78f4216faec7499044fdf65c1b2511 (patch) | |
| tree | 9286fb4b92447c97b0dd1c10c2ddae7fdd60beac /tests | |
| parent | 1b90cdcf23777a53879f92ccdc0b0d453944c596 (diff) | |
Fixed #11293 -- fixed using Q objects to generate ORs with aggregates.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15173 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/aggregation_regress/tests.py | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py index 33e37d6a9a..ec2603fe1e 100644 --- a/tests/regressiontests/aggregation_regress/tests.py +++ b/tests/regressiontests/aggregation_regress/tests.py @@ -4,8 +4,8 @@ from decimal import Decimal from operator import attrgetter from django.core.exceptions import FieldError +from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F, Q from django.test import TestCase, Approximate, skipUnlessDBFeature -from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F from models import Author, Book, Publisher, Clues, Entries, HardbackBook @@ -673,6 +673,58 @@ 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") + ) + @skipUnlessDBFeature('supports_stddev') def test_stddev(self): self.assertEqual( |
