我正在尝试按日期过滤Django-sphinx返回的查询集,但我总是得到未经过滤的查询集。
这是片段:
date_start = form.cleaned_data['date_start']
date_end = form.cleaned_data['date_end']
results = Story.search.query(query).filter(date__range=(date_start, date_end))
证据:
results = Story.search.query(query)
import sys
print>>sys.stderr, "Results before date filtering:"
for i in results:
print>>sys.stderr, i.date
print>>sys.stderr, "Date start"
print>>sys.stderr, date_start
print>>sys.stderr, date_start.__class__
print>>sys.stderr, "Date end"
print>>sys.stderr, date_end
print>>sys.stderr, date_end.__class__
fresults = results.filter(date__range=(date_start,date_end))
print>>sys.stderr, "Results after date filtering:"
for j in fresults:
print>>sys.stderr, j.date
print>>sys.stderr, date_start<=j.date and "OK" or "Error"
print>>sys.stderr, j.date<=date_end and "OK" or "Error"
输出:
Results before date filtering:
2011-09-16 01:46:10
Date start
2011-09-08 00:00:00
<type 'datetime.datetime'>
Date end
2011-09-09 00:00:00
<type 'datetime.datetime'>
Results after date filtering:
2011-09-16 01:46:10
OK
Error
正如您所看到的,在过滤后,仍会返回9月16日的日期,即9月9日的日期(date_end变量)。