Richard
Richard

Reputation: 1307

haystack in a view

Folks. I just can't make the jump from the Haystack tutorial/docs to my (simple) application.

I've got Haystack/Whoosh working per the tutorial, and serving results. Now, instead of a separate search page, I want to search from a form on (say) my archive page and serve the results back into the same page.

I've got this going and showing the search form, and returning the query:

def blog_list(request, template_name="blog/blog_list.html"):
    query=request.GET.get('q','')
    form=ModelSearchForm({'q': query })

    extra_context = {
         'query': query,
        'form': form,
    }
    return object_list(
        request,
        queryset=Entry.live.all(),
        extra_context=extra_context
    )

But in the template, {% for result in page.object_list %} isn't returning anything. Half my problem is that I've no idea where page.object_list is coming from and can't fathom it from the tutorial/documentation.

Can anyone shed some light on this for me? Thank you.

Upvotes: 2

Views: 1304

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599630

You haven't passed in anything called page, so naturally it's empty. It doesn't "come from" anywhere, unless you specifically pass it in.

The bit you don't seem to be doing is actually performing the search and passing the results to the template. Look how it's done in Haystack's built-in basic_search view - it calls the form's .search() method, passes the results to the Paginator class, and then passes that to the context.

Upvotes: 2

Related Questions