开发者

How to filter by date in django-sphinx?

I'm trying to filter by date the queryset that Django-sphinx returns but I am always getting the queryset unfiltered.

This is the snippet:

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

The proof:

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"

Output:

Results before date filtering:
2011-09-16 01:46:10

Date start
2011-09-08 00:00:00
<type 'datetime.date开发者_开发知识库time'>

Date end
2011-09-09 00:00:00
<type 'datetime.datetime'>

Results after date filtering:
2011-09-16 01:46:10
OK
Error

As you can see, after filtering, still returns an entry dated September 16, which is a later date of September 9 (date_end variable).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜