[Django]-Haystack Faceted: __init__() got an unexpected keyword argument 'facet_fields'

9πŸ‘

βœ…

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'),
πŸ‘€solarissmoke

Leave a comment