干草堆搜索以开始为前缀
为什么我使用:
users = SearchQuerySet().all()
users = users.filter(name__startswith='foo')
时会得到查询结果。而当我使用
users = SearchQuerySet().models(UserProfile)
users = users.filter(name__startswith='foo')
时却没有任何结果呢?
谢谢 :)
1 个回答
0
在你所有的模型中,哪个模型里创建了一个 SearchIndex
呢?你有没有为 UserProfile
创建一个 SearchIndex
,类似这样的:
from haystack import indexes
from haystack import site
class UserProfileIndex(indexes.SearchIndex):
...
site.register(UserProfile, UserProfileIndex)
你只能看到那些已经被索引的模型。从你发的代码来看,似乎你并没有为 UserProfile
创建索引,而是为其他一些模型创建了索引。