按日期时间对django haystack结果进行排序(whoosh后端)
我有一个按日期时间对django haystack结果进行排序(whoosh后端),django,datetime,search,django-haystack,whoosh,Django,Datetime,Search,Django Haystack,Whoosh,我有一个SearchIndex,我想根据DatetimeField对其结果进行排序。但是,当我尝试manage.py rebuild\u index时,我收到一个ValueError抱怨datetime是一个。。。日期时间 如果重要的话,我会使用时区和pytz,但是对于我想要的排序,时区其实并不重要,我只想要最新的东西 索引 我删除了一些不相关的字段 class ArticleIndex(indexes.SearchIndex, indexes.Indexable): text = in
SearchIndex
,我想根据DatetimeField
对其结果进行排序。但是,当我尝试manage.py rebuild\u index
时,我收到一个ValueError
抱怨datetime是一个。。。日期时间
如果重要的话,我会使用时区和pytz,但是对于我想要的排序,时区其实并不重要,我只想要最新的东西
索引
我删除了一些不相关的字段
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
publish_date = indexes.DateTimeField(model_attr='publish_date')
视图/url对
posts_sqs = SearchQuerySet().order_by('-publish_date')
urlpatterns += patterns(
'haystack.views',
url(r'^search/$', search_view_factory(
view_class=PostsSearchView,
template='pages/search.html',
searchqueryset=posts_sqs,
form_class=ThreeCharMinSearchForm), # a custom form
name='pages.search'),
)
重建索引异常
ValueError: datetime.datetime(2015, 1, 23, 16, 31, 28, tzinfo=<UTC>) is not unicode or sequence
ValueError:datetime.datetime(2015,1,23,16,31,28,tzinfo=)不是unicode或序列
我已经尝试使用原始和感知的日期时间、时间元组和纪元时间来实现prepare\u publish\u date
方法,这些方法返回strftime
表示('%Y%m%d%H%m'
和'%d%m%Y%H%m'
)使用CharField
而不是DateTimeField
,我记不起还有什么失败了,除了“epoch-time”版本,尽管速度非常慢
最后,我使用了Python2.7.8、Django 1.6.10,在我尝试进行排序之前,索引工作得很好(甚至比预期的更好),因此我非常确定其余的实现是正确的
我知道这是期待unicode的嗖嗖声,但我不知道该怎么做。有什么想法吗?谢谢大家的反馈,因为当没有人回答你的问题时,反馈基本上是“老兄,你说的没有道理,质疑你的假设,检查一切。” 因此,在我的例子中,有一个定制的
WhooshSearchBackend
,它被剥离了,没有考虑DateTimeField
s。对于任何遇到这种情况的人,Whoosh
和Haystack
都可以处理datetime
s。如果没有,请检查您的设置