import datetime
def filter(request):
if 'year_from' and 'month_from' and 'day_from' and\
'year_to' and 'month_to' and 'day_to' in request.GET:
y = request.GET['year_from']
m = request.GET['month_from']
d = request.GET['day_from']
date_from = datetime.datetime(int(y), int(m), int(d), 0, 0)
y = request.GET['year_to']
m = request.GET['month_to']
d = request.GET['day_to']
date_to = datetime.datetime(int(y), int(m), int(d), 0, 0)
else:
print "error time range!"
接下来就可以用获得的 date_from 和date_to作为端点筛选数据库了,需要用到__range函数,将上面代码加上数据库查询动作:
import datetime
def filter(request):
if 'year_from' and 'month_from' and 'day_from' and\
'year