开发者

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

开发者 https://www.devze.com 2023-03-15 15:44 出处:网络
I have a simple Aggregate: tot=PurchaseOrderLine.objects.aggregate(total=Sum(\'price\')) return HttpResponse(tot)

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!


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号