本文整理汇总了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