Django: Calculate the Sum of the column values through query

You’re probably looking for aggregate

from django.db.models import Sum

ItemPrice.objects.aggregate(Sum('price'))
# returns {'price__sum': 1000} for example

Leave a Comment