如何在不同的页面中显示haystack查询?

时间:2014-04-06 13:27:32

标签: django django-views django-haystack

我已经阅读了Haystack入门文档,但我真的在如何将查询集结果传递到单独的页面方面苦苦挣扎。我尝试了几天但没有任何结果。

我已经为搜索创建了自己的视图和表单。我在search.html模板中调用它们,如果在那里显示结果它们正常工作。但是,我不知道如何将所有结果传递给results.html模板。

您能否帮我定义如何在结果视图中接收参数。我非常感激。

views.py

class InstitutionSearchView(SearchView):
    __name__ = 'InstitutionSearchView'
    template = 'search/search.html'

    def __init__(self, *args, **kwargs):
        # Needed to switch out the default form class.
        if kwargs.get('form_class') is None:
            kwargs['form_class'] = InstitutionSearchForm

        super(InstitutionSearchView, self).__init__(*args, **kwargs)


def search(request):
    sqs = SearchQuerySet().facet('type_institution').facet('levels').facet('languages').facet('location')
    form = InstitutionSearchForm(request.GET)
    if form.is_valid():
        cd = form.cleaned_data

    return InstitutionSearchView(form_class=InstitutionSearchForm, searchqueryset=sqs)(request)


def results(request, *args, **kwargs):
    return render_to_response('search/results.html', locals(), 
        context_instance=RequestContext(request))

urls.py

urlpatterns = patterns('', 
    url(r'^$',  views.search, name='haystack_search'),
    url(r'^results',  views.results, name='results'),)

search.html

<div class="span12">
    <h1>Search</h1>
     <form method="get" action="{% url 'institution:results' %}" class=".form-search">
        <table>
           {{ form.as_table }}
    </table>
    <input type="submit" value="Search">
</form>

results.html

{% if query %}
 results
{% endif %}

0 个答案:

没有答案