GrantsV
GrantsV

Reputation: 3

Django Python noob - how do I get the NUMBER out of a Aggregate sum?

I have a simple Aggregate:

    tot=PurchaseOrderLine.objects.aggregate(total=Sum('price'))
    return HttpResponse(tot)

This returns "total".

If I do:

    return HttpResponse(str(tot))

It displays "{'total': Decimal('321.60')}"

How do I get the NUMERIC var out of this!

Upvotes: 0

Views: 93

Answers (1)

Udi
Udi

Reputation: 30482

tot=PurchaseOrderLine.objects.aggregate(total=Sum('price'))['total'] 
return HttpResponse(tot)

Upvotes: 1

Related Questions