Skip to content

Commit 3f40cea

Browse files
committed
Fixed a doc example on custom forms. Thanks to GrivIN and benspaulding for patches.
1 parent a1a3017 commit 3f40cea

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

docs/views_and_forms.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,27 @@ associated with it. You might create a form that looked as follows::
8787

8888
from django import forms
8989
from haystack.forms import SearchForm
90-
91-
90+
91+
9292
class DateRangeSearchForm(SearchForm):
9393
start_date = forms.DateField(required=False)
9494
end_date = forms.DateField(required=False)
95-
95+
9696
def search(self):
9797
# First, store the SearchQuerySet received from other processing.
9898
sqs = super(DateRangeSearchForm, self).search()
99-
99+
100+
if not self.is_valid():
101+
return self.no_query_found()
102+
100103
# Check to see if a start_date was chosen.
101104
if self.cleaned_data['start_date']:
102105
sqs = sqs.filter(pub_date__gte=self.cleaned_data['start_date'])
103-
106+
104107
# Check to see if an end_date was chosen.
105108
if self.cleaned_data['end_date']:
106109
sqs = sqs.filter(pub_date__lte=self.cleaned_data['end_date'])
107-
110+
108111
return sqs
109112

110113
This form adds two new fields for (optionally) choosing the start and end dates.
@@ -150,9 +153,9 @@ URLconf should look something like::
150153
from haystack.forms import ModelSearchForm
151154
from haystack.query import SearchQuerySet
152155
from haystack.views import SearchView
153-
156+
154157
sqs = SearchQuerySet().filter(author='john')
155-
158+
156159
# Without threading...
157160
urlpatterns = patterns('haystack.views',
158161
url(r'^$', SearchView(
@@ -161,10 +164,10 @@ URLconf should look something like::
161164
form_class=SearchForm
162165
), name='haystack_search'),
163166
)
164-
167+
165168
# With threading...
166169
from haystack.views import SearchView, search_view_factory
167-
170+
168171
urlpatterns = patterns('haystack.views',
169172
url(r'^$', search_view_factory(
170173
view_class=SearchView,

0 commit comments

Comments
 (0)