django haystack - using a generic Views function to do search
django, django-haystack, django-urls, django-views
Solution
The `search_view_factory` returns a view function instead of an `HttpResponse`, you need to invoke it properly.
def search(request):
sqs = SearchQuerySet().all()
view = search_view_factory(
view_class=SearchView,
template='search/search.html',
searchqueryset=sqs,
form_class=HighlightedSearchForm
)
return view(request)
Sorry for misleading in your previous question, I've fixed it also.
Problem
I'm trying to convert this code from haystack into urls.py calling a generic view function, but I'm getting 'function' object has no attribute 'status_code'. I think it's because it's not returning a response object. haystack code: ``` from django.conf.urls.defaults import * from haystack.forms import ModelSearchForm, HighlightedSearchForm from haystack.query import SearchQuerySet from haystack.views import SearchView sqs = SearchQuerySet().filter(author='john') # With threading... from haystack.views import SearchView, search_view_factory urlpatterns = patterns('haystack.views', url(r'^$', search_view_factory( view_class=SearchView, template='search/search.html', searchqueryset=sqs, form_class=HighlightedSearchForm ), name='haystack_search'), ) ``` My new urls.py just calls search() in views.py. In views.py, I have ``` def search(request): sqs = SearchQuerySet().all() return search_view_factory( view_class=SearchView, template='search/search.html', searchqueryset=sqs, form_class=HighlightedSearchForm ) ``` I'm doing this because I want to mess around with sqs quite a bit depending on user inputs and status. Shouldn't search_view_factory above return a SearchView class, seems like it calls create_response() automatically which returns render_to_response. Tried calling create_response() manually, but that wasn't working either. django-haystack code can be found here. Thank you.