简体   繁体   中英

Filter blank CharField in Django Haystack's SearchQuerySet

I need to return all entries in a SearchQuerySet where a certain CharField is blank ie an empty string.

In my search_indexes.py I have:

sometext = indexes.CharField(model_attr='sometext')

I've tried filtering using the usual SQS syntax:

SearchQuerySet().filter(sometext__exact='')
SearchQuerySet().filter(sometext__in=['', None])

Neither return only the blank entries. The first returns all entries, the second returns none at all.

Am I missing something in my SearchIndex definitions? Is there any way this can be done in Haystack using the Whoosh backend?

try this, it works for me:

from haystack.inputs import Raw
r = SearchQuerySet()
r.exclude(sometext=Raw('*'))

你可以这样做:

    SomeQuerySet().filter(sometext='')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM