I want to add an extra field to Haystack
form, but for some reason, the form output in template isn't working.
Instead of displaying extra field, I get some weird template with model select fields. All I want is a single q
input and an extra field for author
.
forms.py
from django import forms
from haystack.forms import HighlightedSearchForm
class QuestionSearchForm(HighlightedSearchForm):
author = forms.CharField(max_length = 100, required = False)
views.py
# Create your views here.
from haystack.generic_views import SearchView
from search.forms import QuestionSearchForm
class QuestionSearchView(SearchView):
form_class = QuestionSearchForm
template_name = 'search/search.html'
search/search.html
<form method="get" class="form-inline" action=".">
<div>
{{ form.as_p }}
<input class="btn btn-primary" type="submit" value="Najdi"/>
</div>
</form>
Output:
Thanks!
I believe template_name
should be template
in your views.py.
Take a look at the default class SearchView
on the haystack Github page.