Haystack Faceted:__init __()得到了一个意想不到的关键字参数'facet_fields' [英] Haystack Faceted: __init__() got an unexpected keyword argument 'facet_fields'

查看:193
本文介绍了Haystack Faceted:__init __()得到了一个意想不到的关键字参数'facet_fields'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用haystack 2.4.1(Django 1.8)享受我的第一个结果时,我不得不承认我很难学习。文档有时是不完整的,一些功能不得不说。



面搜索是其中之一。



我正在遵循文档和网址。 py:

  urlpatterns = patterns('haystack.views',
url(r'^ $',FacetedSearchView form_class = FacetedSearchForm,facet_fields = ['author']),name ='haystack_search'),

我收到以下错误:


/ tag_analytics / faceted_search / p>

__ init __()得到一个意想不到的关键字参数'facet_fields'


看起来FacetSearchView不接受 facet_fields 参数,这使我进入2.4.0版,当正确的方法是

  FacetedSearc hView(form_class = FacetedSearchForm,searchqueryset = sqs)

虽然我确定我的版本是2.4.1 ,我尝试了这个选项,并在/ tag_analytics / faceted_search /

$ a $ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

切片索引必须是整数或无或具有__index__方法


提前感谢任何线索!



最好的
alan

解决方案

文档是错误的,令人困惑。您不能将 facet_fields 传递给 FacetedSearchView 的构造函数。



你采取的方法是正确的,虽然不是把所有这些参数放在 url 定义中,但是你应该创建自己的视图,如下所示:

 #tag_analytics / views.py 
from haystack.generic_views import FacetedSearchView as BaseFacetedSearchView

#现在创建自己的子类基础视图
class FacetedSearchView(BaseFacetedSearchView):
form_class = FacetedSearchForm
facet_fields = ['author']
template_name ='search.html'
context_object_name =' page_object'

#...任何其他自定义方法等

然后在 urls.py

  from tag_analytics.views import FacetedSearchView 
#...
url(r'^ $',FacetedSearchView.as_view(),name ='haystack_search'),


While enjoying my first results with haystack 2.4.1 (Django 1.8), I have to admit that I'm having a hard time on learning it. The documentation is sometimes incomplete, and some features have to few examples.

Faceted search is one of them.

I'm following the documentation, and at the url.py:

urlpatterns = patterns('haystack.views',
    url(r'^$', FacetedSearchView(form_class=FacetedSearchForm, facet_fields=['author']), name='haystack_search'),
)

I'm getting the following error:

TypeError at /tag_analytics/faceted_search/

__init__() got an unexpected keyword argument 'facet_fields'

Looks like the FacetSearchView is not accepting the facet_fields argument, which took me to version 2.4.0, when the right way to do this was

FacetedSearchView(form_class=FacetedSearchForm, searchqueryset=sqs)

Although I'm sure my version is 2.4.1, I tried this option, and got a

TypeError at /tag_analytics/faceted_search/

slice indices must be integers or None or have an __index__ method

Thanks in advance for any clues!

the best, alan

解决方案

The documentation is just wrong, and confusing. You cannot pass facet_fields to the constructor for FacetedSearchView.

The approach you have taken is correct although rather than put all those arguments in the url definition, you should create your own view - something like this:

# tag_analytics/views.py
from haystack.generic_views import FacetedSearchView as BaseFacetedSearchView

# Now create your own that subclasses the base view
class FacetedSearchView(BaseFacetedSearchView):
    form_class = FacetedSearchForm
    facet_fields = ['author']
    template_name = 'search.html'
    context_object_name = 'page_object'

    # ... Any other custom methods etc

Then in urls.py:

from tag_analytics.views import FacetedSearchView
#...
url(r'^$', FacetedSearchView.as_view(), name='haystack_search'),

这篇关于Haystack Faceted:__init __()得到了一个意想不到的关键字参数'facet_fields'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆