Django complex queries
- by Josh K
I need to craft a filter for an object that checks date ranges. Right now I'm performing a very inefficient loop which checks all the objects. I would like to simplify this to a database call.
The logic is you have a start and an end date objects. I need to check if the start OR the end is within the range of an appointment.
if (start >= appointment.start && start < appointment.end) ||
(end > appointment.start && end <= appointment.end)
I could do this in SQL, but I'm not as familiar with the Django model structure for more complex queries.