|
1 | 1 | import datetime
|
2 | 2 | from decimal import Decimal
|
| 3 | +from unittest import skipIf |
3 | 4 |
|
4 | 5 | from django.core.exceptions import FieldDoesNotExist, FieldError
|
| 6 | +from django.db import connection |
5 | 7 | from django.db.models import (
|
6 |
| - BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func, |
7 |
| - IntegerField, NullBooleanField, OuterRef, Q, Subquery, Sum, Value, |
| 8 | + BooleanField, CharField, Count, DateTimeField, Exists, ExpressionWrapper, |
| 9 | + F, Func, IntegerField, Max, NullBooleanField, OuterRef, Q, Subquery, Sum, |
| 10 | + Value, |
8 | 11 | )
|
9 | 12 | from django.db.models.expressions import RawSQL
|
10 | 13 | from django.db.models.functions import Length, Lower
|
@@ -619,3 +622,16 @@ def test_annotation_filter_with_subquery(self):
|
619 | 622 | total_books=Subquery(long_books_qs, output_field=IntegerField()),
|
620 | 623 | ).values('name')
|
621 | 624 | self.assertCountEqual(publisher_books_qs, [{'name': 'Sams'}, {'name': 'Morgan Kaufmann'}])
|
| 625 | + |
| 626 | + @skipIf(connection.vendor == 'oracle', 'See https://code.djangoproject.com/ticket/31584') |
| 627 | + def test_annotation_exists_aggregate_values_chaining(self): |
| 628 | + qs = Book.objects.values('publisher').annotate( |
| 629 | + has_authors=Exists(Book.authors.through.objects.filter(book=OuterRef('pk'))), |
| 630 | + max_pubdate=Max('pubdate'), |
| 631 | + ).values_list('max_pubdate', flat=True).order_by('max_pubdate') |
| 632 | + self.assertCountEqual(qs, [ |
| 633 | + datetime.date(1991, 10, 15), |
| 634 | + datetime.date(2008, 3, 3), |
| 635 | + datetime.date(2008, 6, 23), |
| 636 | + datetime.date(2008, 11, 3), |
| 637 | + ]) |
0 commit comments