Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Created August 14, 2013 08:05
Show Gist options
  • Save toast38coza/6228903 to your computer and use it in GitHub Desktop.
Save toast38coza/6228903 to your computer and use it in GitHub Desktop.
Return all results from a Django-Haystack search even if there is no query provided
from haystack.forms import FacetedSearchForm
class ShowResultsSearchForm(FacetedSearchForm):
"""
This example extends the FacetedSearchForm - you could just as easily extend SearchForm
"""
def __init__(self, *args, **kwargs):
super(BrowseFilterSearchForm, self).__init__(*args, **kwargs)
def no_query_found(self):
"""
Overwrite the defult no_query_found method - instead of returning empty query, return .all()
"""
return self.searchqueryset.all()
from myapp.forms import ShowResultsSearchForm
url(r'^$', FacetedSearchView(
form_class=ShowResultsSearchForm,
searchqueryset=SearchQuerySet().all()),
name='haystack_faceted_search'),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment