Reputation: 59
Assuming you have a Page model with a '''visits_count (IntegerField)''' field, how do you calculate the arithmetic mean of the number of visits for all pages in the database?
Upvotes: 1
Views: 592
Reputation: 476557
You can aggregate over the Page
s:
from django.db.models import Avg
avg_visits = Page.objects.aggregate(
avg_visits=Avg('visits_count')
)['avg_visits']
Upvotes: 1