@@ -87,24 +87,27 @@ associated with it. You might create a form that looked as follows::
87
87
88
88
from django import forms
89
89
from haystack.forms import SearchForm
90
-
91
-
90
+
91
+
92
92
class DateRangeSearchForm(SearchForm):
93
93
start_date = forms.DateField(required=False)
94
94
end_date = forms.DateField(required=False)
95
-
95
+
96
96
def search(self):
97
97
# First, store the SearchQuerySet received from other processing.
98
98
sqs = super(DateRangeSearchForm, self).search()
99
-
99
+
100
+ if not self.is_valid():
101
+ return self.no_query_found()
102
+
100
103
# Check to see if a start_date was chosen.
101
104
if self.cleaned_data['start_date']:
102
105
sqs = sqs.filter(pub_date__gte=self.cleaned_data['start_date'])
103
-
106
+
104
107
# Check to see if an end_date was chosen.
105
108
if self.cleaned_data['end_date']:
106
109
sqs = sqs.filter(pub_date__lte=self.cleaned_data['end_date'])
107
-
110
+
108
111
return sqs
109
112
110
113
This form adds two new fields for (optionally) choosing the start and end dates.
@@ -150,9 +153,9 @@ URLconf should look something like::
150
153
from haystack.forms import ModelSearchForm
151
154
from haystack.query import SearchQuerySet
152
155
from haystack.views import SearchView
153
-
156
+
154
157
sqs = SearchQuerySet().filter(author='john')
155
-
158
+
156
159
# Without threading...
157
160
urlpatterns = patterns('haystack.views',
158
161
url(r'^$', SearchView(
@@ -161,10 +164,10 @@ URLconf should look something like::
161
164
form_class=SearchForm
162
165
), name='haystack_search'),
163
166
)
164
-
167
+
165
168
# With threading...
166
169
from haystack.views import SearchView, search_view_factory
167
-
170
+
168
171
urlpatterns = patterns('haystack.views',
169
172
url(r'^$', search_view_factory(
170
173
view_class=SearchView,
0 commit comments