Peterkm
Peterkm

Reputation: 41

How to get a sum from a Django filter query

I have used the following query, and I am trying to get the Sum of 'fee'

reg_total_fees =orders.aggregate(all_sum=Sum('par_payment__fee'))

but I get this: {'all_sum': 1785}

Do you know how I could just get the value?

Upvotes: 0

Views: 392

Answers (3)

Kian Edjtehadi
Kian Edjtehadi

Reputation: 1

reg_total_fees = orders.objects.filter(write your interesting attribute for filtering =expected value for filttering).aggregate(Sum('par_payment__fee'))['par_payment__fee__sum']

Upvotes: 0

Ashish Nautiyal
Ashish Nautiyal

Reputation: 931

Just access the key 'all_sum' from dictionary reg_total_fees.Below line will give you the value you need.

reg_total_fees =orders.aggregate(all_sum=Sum('par_payment__fee'))['all_sum']

Upvotes: 0

OlegТ
OlegТ

Reputation: 181

reg_total_fees =orders.aggregate(all_sum=Sum('par_payment__fee'))['all_sum']

Upvotes: 1

Related Questions