本文整理匯總了Python中wagtail.wagtailsearch.index.SearchField方法的典型用法代碼示例。如果您正苦於以下問題:Python index.SearchField方法的具體用法?Python index.SearchField怎麽用?Python index.SearchField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.wagtailsearch.index
的用法示例。
在下文中一共展示了index.SearchField方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: prepare_field
# 需要導入模塊: from wagtail.wagtailsearch import index [as 別名]
# 或者: from wagtail.wagtailsearch.index import SearchField [as 別名]
def prepare_field(self, obj, field):
if isinstance(field, SearchField):
yield (unidecode(self.prepare_value(field.get_value(obj))),
get_weight(field.boost))
elif isinstance(field, RelatedFields):
sub_obj = getattr(obj, field.field_name)
if sub_obj is None:
return
if callable(sub_obj):
sub_obj = sub_obj()
if isinstance(sub_obj, Manager):
sub_objs = sub_obj.all()
else:
sub_objs = [sub_obj]
for sub_obj in sub_objs:
for sub_field in field.fields:
for value in self.prepare_field(sub_obj, sub_field):
yield value
示例2: get_search_fields
# 需要導入模塊: from wagtail.wagtailsearch import index [as 別名]
# 或者: from wagtail.wagtailsearch.index import SearchField [as 別名]
def get_search_fields(search_fields):
for search_field in search_fields:
if isinstance(search_field, SearchField):
yield search_field
elif isinstance(search_field, RelatedFields):
for sub_field in get_search_fields(search_field.fields):
yield sub_field