Aggregation With F() In Django Rest Api

[Solved] Aggregation With F() In Django Rest Api | Python Frameworks Django - Code Explorer | www.yomemimo.com
Question : aggregation with f() in django rest api

Answered by : silly-swan-zgo6gde6ph92

>>> from django.db.models import Avg, Count
>>> Book.objects.annotate(num_authors=Count('authors')).aggregate(Avg('num_authors'))
{'num_authors__avg': 1.66}

Source : https://docs.djangoproject.com/en/3.1/topics/db/aggregation/#aggregating-annotations | Last Update : Tue, 02 Mar 21

Answers related to aggregation with f() in django rest api

Code Explorer Popular Question For Python Frameworks Django