开发者

django haystack - class-based view

开发者 https://www.devze.com 2023-03-30 16:16 出处:网络
Are there any tutorials or examples besides the one on the official haystack web site on how to use the c开发者_Python百科lass-based views?

Are there any tutorials or examples besides the one on the official haystack web site on how to use the c开发者_Python百科lass-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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消