6👍
Have you looked at the faceting tutorial/documentation on the django-haystack website? It walks you through an example of filtering based on author of the Note
model introduced in the getting started tutorial.
Another option separate from haystack and searching is django-filter
by Alex Gaynor, it allows you to filter fields based on the contents of the model and not on an index. Therefore it can be used on models that aren’t indexed with django-haystack
. You can check out the repository here. There are good docs in the doc folder and the included tests show off all the functionality.
0👍
if we summarize how to add haystack faceting
- you need to add faceted fields to your index model
title = CharField(model_attr='title', faceted=True) description = CharField(model_attr='description', faceted=True)
- change your queryset to
sqs = SearchQuerySet().facet('title').facet('description')
- use faceted versions of search form and view that haystack provides in urls.py use this
url(r'^$', FacetedSearchView(form_class=FacetedSearchForm, searchqueryset=sqs), name='haystack_search'),
-
add faceting part to your template like this http://docs.haystacksearch.org/dev/faceting.html#display-the-facets-in-the-template
-
rebuild your index to see effects of faceting
python manage.py rebuild_index
- [Django]-Django using curry to build formsets with custom form
- [Django]-Django-allauth, recommendations for limiting failed login attempts
- [Django]-Dealing with legacy django project in new localized projects