gadss
gadss

Reputation: 22489

How do I convert this SQL to Django QuerySet?

I have this SQL

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

and it returns :
enter image description here

and i try to convert it to django queryset:

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

but it returns an empty set...

is my django queryset didn't convert my SQL? can anyone can give me an idea on how can I convert my SQL to django queryset?

thanks in advance...

Upvotes: 3

Views: 1787

Answers (1)

DrTyrsa
DrTyrsa

Reputation: 31951

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

Upvotes: 4

Related Questions