summaryrefslogtreecommitdiff
path: root/tests/annotations
diff options
context:
space:
mode:
Diffstat (limited to 'tests/annotations')
-rw-r--r--tests/annotations/tests.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index 9f35074934..aa3682b86b 100644
--- a/tests/annotations/tests.py
+++ b/tests/annotations/tests.py
@@ -6,8 +6,8 @@ from django.core.exceptions import FieldDoesNotExist, FieldError
from django.db import connection
from django.db.models import (
BooleanField, Case, CharField, Count, DateTimeField, Exists,
- ExpressionWrapper, F, Func, IntegerField, Max, NullBooleanField, OuterRef,
- Q, Subquery, Sum, Value, When,
+ ExpressionWrapper, F, FloatField, Func, IntegerField, Max,
+ NullBooleanField, OuterRef, Q, Subquery, Sum, Value, When,
)
from django.db.models.expressions import RawSQL
from django.db.models.functions import Length, Lower
@@ -178,6 +178,14 @@ class NonAggregateAnnotationTestCase(TestCase):
self.assertEqual(book.combined, 12)
self.assertEqual(book.rating_count, 1)
+ def test_combined_f_expression_annotation_with_aggregation(self):
+ book = Book.objects.filter(isbn='159059725').annotate(
+ combined=ExpressionWrapper(F('price') * F('pages'), output_field=FloatField()),
+ rating_count=Count('rating'),
+ ).first()
+ self.assertEqual(book.combined, 13410.0)
+ self.assertEqual(book.rating_count, 1)
+
def test_aggregate_over_annotation(self):
agg = Author.objects.annotate(other_age=F('age')).aggregate(otherage_sum=Sum('other_age'))
other_agg = Author.objects.aggregate(age_sum=Sum('age'))