avatar
avatar

Reputation: 12495

django haystack - class-based view

Are there any tutorials or examples besides the one on the official haystack web site on how to use the class-based views?

What I actually need is to be able to show results from multiple models when a user does a search and from what I understand I will need crate my own view and inherit from SearchView but the example on the official web site it's not sufficient for me.

Upvotes: 2

Views: 528

Answers (2)

Adam Spence
Adam Spence

Reputation: 3240

The default views in Haystack aren't proper or should I say typical Class based views. As far as I know they are unique to Haystack.

Saying that, its not too difficult to subclass them, just do something like:

class CustomSearchView(FacetedSearchView):
    def create_response(self):
        if self.request.method == 'POST':
            ....

        if self.request.method == 'GET':
            ....

        return super(CustomSearchView, self).create_response()

    def extra_context(self):
        # add your context

As you can see, they are somewhere between Class based views and Function based views.

In your case you'll probably need to create SearchIndexes for all your models and then all you will have to do is get your initial query correct in urls.py

Upvotes: 0

Kambiz
Kambiz

Reputation: 1217

In these cases the best way of learning is to explore source codes and find the way they work, then you can override methods you want

Upvotes: 1

Related Questions