1 # Custom Haystack search form for autocomplete searches
3 from haystack
.forms
import SearchForm
6 class autocomplete_search_form(SearchForm
):
8 Custom Haystack search form for autocomplete searches. Important so that
9 users can search for 'foo' and get 'foo.bar', 'foo.bar.herp', etc.
13 Overwriting SearchForm's default search to implement autocomplete
16 if not self
.is_valid():
17 return self
.no_query_found()
19 if not self
.cleaned_data
.get('q'):
20 return self
.no_query_found()
22 # Perform an autocomplete search query on the 'content_auto' fields of
23 # the searchable models
24 sqs
= self
.searchqueryset
.autocomplete(content_auto
=self
.cleaned_data
['q'])