我有这个SQL
select product_id, date_booked, sum(quantity) from booking_hotelcheck where client_id=1 and status='Complete'
group by product_id, date_booked
然后返回:
我尝试将其转换为django queryset:
>>> HotelCheck.objects.filter(client=1,status='Complete').values('product','date_booked','quantity').aggregate(Sum('quantity'))
{}
>>>
但它返回一个空集......
是我的django queryset没有转换我的SQL? 任何人都可以告诉我如何将我的SQL转换为django queryset?
提前感谢...
答案 0 :(得分:4)
HotelCheck.objects.filter(client=1, status='Complete').values('product','date_booked').annotate(Sum('quantity'))