简体   繁体   中英

haystack search startswith

Why when i use:

users = SearchQuerySet().all()
users = users.filter(name__startswith='foo')

i have query with result. And when i use

users = SearchQuerySet().models(UserProfile)
users = users.filter(name__startswith='foo')

i have empty query

Thx :)

From all your models, in which one did you create a SearchIndex ? Do you have a SearchIndex for UserProfile , something like:

from haystack import indexes
from haystack import site


class UserProfileIndex(indexes.SearchIndex):
    ...

site.register(UserProfile, UserProfileIndex)

You can only see models that you have indexed. From the code you've posted, it looks like you haven't indexed UserProfile but some other models.

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