Django — Aggregate Sum of All Fields

Well, the docs as of today on aggregation don’t mention anything about the specific types of Aggregation possible. It mentions Avg, Min, Count, etc.

Update from Derek below: actually, it’s in the docs in the Queryset API docs under “Aggregation Functions”
Missed that… but there should be a link back there from the main aggregation docs.

Anyhoo, I found another type Sum in django.db.models.

Just apply
MyQueryset.aggregate(Sum('my_field')) to get the sum of all my_fields in your queryset.

5 thoughts on “Django — Aggregate Sum of All Fields

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s