嗨,大家好,任何人都有與我一樣的問題。問題出在Django Rest Query上,其中我從數據庫中的字段求和值。Django Rest Framewrok與總和查詢問題
我得到錯誤:
- Django的版本:1.7.7
- 異常類型:類型錯誤
- 異常值: '小數' 對象不是可迭代
意見
class invoiceList(APIView):
@method_decorator(ensure_csrf_cookie)
def get(self, request, format=None):
user_pk = request.user.id
org_id = request.user.organization.id
total = OutgoingInvoice.objects.filter(organization_id=user_pk, status_id__in=[2,3]).aggregate(total=Sum('total_invoice_amount', field="total_invoice_amount"))['total']
serializer = OutgoingInvo(total, many=True)
return Response(serializer.data)
而我的模型是:
total_invoice_amount = models.DecimalField(decimal_places=5, max_digits=255, blank=True, null=True)
請發佈您的stacktrace以獲取有關此錯誤的更多詳細信息。 – Jingo