diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index c1073d6f41..59ad116ef3 100644
a
|
b
|
from decimal import Decimal
|
4 | 4 | from django.core.exceptions import FieldDoesNotExist, FieldError |
5 | 5 | from django.db.models import ( |
6 | 6 | BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func, |
7 | | IntegerField, NullBooleanField, Q, Sum, Value, |
| 7 | IntegerField, NullBooleanField, OuterRef, Q, Subquery, Sum, Value, |
8 | 8 | ) |
9 | 9 | from django.db.models.expressions import RawSQL |
10 | 10 | from django.db.models.functions import Length, Lower |
… |
… |
class NonAggregateAnnotationTestCase(TestCase):
|
585 | 585 | qs, |
586 | 586 | [{'jacob_name': 'Jacob Kaplan-Moss', 'james_name': 'James Bennett'}], |
587 | 587 | ) |
| 588 | |
| 589 | def test_annotation_filter_with_subquery(self): |
| 590 | long_books_qs = Book.objects.filter( |
| 591 | publisher=OuterRef('pk'), |
| 592 | pages__gt=400, |
| 593 | ).values('publisher').annotate(count=Count('pk')).values('count') |
| 594 | |
| 595 | publisher_books_qs = Publisher.objects.annotate( |
| 596 | total_books=Count('book'), |
| 597 | ).filter( |
| 598 | total_books=Subquery(long_books_qs, output_field=IntegerField()), |
| 599 | ).values('name') |
| 600 | self.assertCountEqual(publisher_books_qs, [{'name': 'Sams'}, {'name': 'Morgan Kaufmann'}]) |