Django complex queries

Posted by Josh K on Stack Overflow See other posts from Stack Overflow or by Josh K
Published on 2011-01-13T18:42:34Z Indexed on 2011/01/13 18:53 UTC
Read the original article Hit count: 234

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about python

Related posts about sql