Skip to content

Commit bc9c6fe

Browse files
committed
[1.11.x] Fixed #28233 -- Used a simpler example in the aggregation "cheat sheet" docs.
Backport of 49b9c89 from master
1 parent 992f143 commit bc9c6fe

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/topics/db/aggregation.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ In a hurry? Here's how to do common aggregate queries, assuming the models above
6767
>>> Book.objects.all().aggregate(Max('price'))
6868
{'price__max': Decimal('81.20')}
6969

70-
# Cost per page
71-
>>> from django.db.models import F, FloatField, Sum
72-
>>> Book.objects.all().aggregate(
73-
... price_per_page=Sum(F('price')/F('pages'), output_field=FloatField()))
74-
{'price_per_page': 0.4470664529184653}
70+
# Difference between the highest priced book and the average price of all books.
71+
>>> from django.db.models import FloatField
72+
>>> Book.objects.aggregate(
73+
... price_diff=Max('price', output_field=FloatField()) - Avg('price')))
74+
{'price_diff': 46.85}
7575

7676
# All the following queries involve traversing the Book<->Publisher
7777
# foreign key relationship backwards.

0 commit comments

Comments
 (0)