Select between two dates with Django

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 how could this be achieved using the Django ORM?

This is where I want to add the between dates of 30 days in my query:

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')

使用__range运算符:

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

__range

链接地址: http://www.djcxy.com/p/38702.html

上一篇: Django ORM“获得”到SQL的翻译

下一篇: 用Django选择两个日期