tags:

views:

31

answers:

2

Hi, I am looking to make a query that selects between dates with Django. I know how to do this with raw sql pretty easily but using the Django ORM, how could this be achieved.

basically,

start_date = datetime.datetime.now() + datetime.timedelta(-30)
context[self.varname] = self.model._default_manager.filter(
    current_issue__isnull=True
    ).live().order_by('-created_at')

The above query is where I want to add the between dates of 30 days in my query.

Any tips?

+1  A: 

__range

Ignacio Vazquez-Abrams
+4  A: 

Use the __range operator:

...filter(current_issue__isnull=True, created_at__range=(start_date, end_date))
Daniel Roseman