문제

I have a search working fine on my project. But in my models I have a boolean field named is_active.

I want the search occurs only when is_active is True, but I've been testing this without any satisfatory response.

my search_indexes.py:

    from haystack.indexes import *
    from haystack.sites import site
    from core.models import AnuncioSolucao

    class AnuncioSolucaoIndex(RealTimeSearchIndex):
        text = CharField(document=True,use_template=True)

    site.register(AnuncioSolucao,AnuncioSolucaoIndex)

That way it works, but also bring me all the is_active == False. Any thoughts?

도움이 되었습니까?

해결책

There's a method called read_queryset on the SearchIndex API. I just had to override this:

class AnuncioSolucaoIndex(RealTimeSearchIndex):
    text = CharField(document=True,use_template=True)
    def read_queryset(self):
        super(AnuncioSolucaoIndex,self).read_queryset()
        return AnuncioSolucao.objects.filter(is_active=True)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top