开发者

Force Haystack to index first letter of Charfield

开发者 https://www.devze.com 2023-04-11 07:35 出处:网络
I have a model开发者_如何转开发 with CharField() class MyModel(models.Model) field = models.CharField(...)

I have a model开发者_如何转开发 with CharField()

class MyModel(models.Model)
   field = models.CharField(...)

How can I configure Haystack to index first letter of this field in SearchIndex?

class MyIndex(SearchIndex):
   starts_with = CharFiled(?)


I found out that Haystack has something like Django`s forms clean functions which is called prepare.

So in my case to get first letter from field I can do:

class MyIndex(SearchIndex): starts_with = CharField()

def prepare_starts_with(self, obj):
    return obj.field[:1]
0

精彩评论

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