如何将此SQL转换为Django QuerySet?

时间:2012-02-17 08:50:23

标签: python sql django django-queryset

我有这个SQL

select product_id, date_booked, sum(quantity) from booking_hotelcheck where client_id=1 and status='Complete'
group by product_id, date_booked

然后返回:
enter image description here

我尝试将其转换为django queryset:

>>> HotelCheck.objects.filter(client=1,status='Complete').values('product','date_booked','quantity').aggregate(Sum('quantity'))
{}
>>>

但它返回一个空集......

是我的django queryset没有转换我的SQL? 任何人都可以告诉我如何将我的SQL转换为django queryset?

提前感谢...

1 个答案:

答案 0 :(得分:4)

HotelCheck.objects.filter(client=1, status='Complete').values('product','date_booked').annotate(Sum('quantity'))