Let's say I have the following table:
Employee
name start_date end_date
John 2009-10-10 2009-12-31
Joe 2009-12-01 2010-05-10
I also have a curr_date
= '2009-11-01'. If I want to get all employees where curr_date
should be between an employee's start_date
and end_date
inclusive, the corresponding SQL is:
SELECT *
FROM employee
WHERE curr_date between start_date and end_date
The corresponding Django QuerySet I came up with is:
Employee.objects.filter(start_date__lte=curr_date, end_date__gte=curr_date)
Is there an alternate way to do the above with Django's QuerySet, the __range
method doesn't quite work for the above case.