Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 848
gadss Avatar asked Dec 29 '25 11:12

gadss


1 Answers

HotelCheck.objects.filter(client=1, status='Complete').values('product','date_booked').annotate(Sum('quantity'))
like image 115
DrTyrsa Avatar answered Jan 01 '26 00:01

DrTyrsa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!