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]
精彩评论