How append sum of instances within a django queryset to that queryset?

前端 未结 1 1488
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 04:10

I have a Django Queryset object that looks like this (it is a derived queryset, not a queryset for a Model):



        
1条回答
  •  一整个雨季
    2021-01-25 04:29

    I don't think you can do that. But if you use aggregate then you will be able to get the sum of A, B, C like this:

    >> result = YourModel.objects.aggregate(A=Sum('A'), B=Sum('B'), C=Sum('C'))
    >> print(result)
    

    0 讨论(0)
提交回复
热议问题