Ticket #29542: 29542.diff

File 29542.diff, 1.3 KB (added by felixxm, 20 months ago)

Test.

  • tests/annotations/tests.py

    diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
    index c1073d6f41..59ad116ef3 100644
    a b from decimal import Decimal 
    44from django.core.exceptions import FieldDoesNotExist, FieldError
    55from django.db.models import (
    66    BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func,
    7     IntegerField, NullBooleanField, Q, Sum, Value,
     7    IntegerField, NullBooleanField, OuterRef, Q, Subquery, Sum, Value,
    88)
    99from django.db.models.expressions import RawSQL
    1010from django.db.models.functions import Length, Lower
    class NonAggregateAnnotationTestCase(TestCase): 
    585585            qs,
    586586            [{'jacob_name': 'Jacob Kaplan-Moss', 'james_name': 'James Bennett'}],
    587587        )
     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'}])
Back to Top