How are you? I need some help please. I am working in Django and I need to make a query of all sales between 00:00 and 00:30 minutes, so every 30 minutes I need to see the sales. I was putting together something like this but it is not working.
sales = (
SalesOrder
.objects
.annotate(Sum('subtotal'))
.filter(created_at__time__range= ('00:00:00:00', ''))
.filter(created_at__time = hour_now)
)
This is a SQL query that delivers the correct data.
SELECT sum(subtotal) as tot
FROM sales_salesorder ss
where extract(minute from created_at::time) between 31 and 59 and
created_at::date = now()::date and
extract(hour from created_at) = extract(hour from CURRENT_TIME);
The problem is that I can't leave the sql query because I have to pass it through a for loop to return the data, that's why the most effective way is to use the ORM, that's the reason of my question.