本文整理匯總了Python中rest_framework.fields.DictField方法的典型用法代碼示例。如果您正苦於以下問題:Python fields.DictField方法的具體用法?Python fields.DictField怎麽用?Python fields.DictField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rest_framework.fields
的用法示例。
在下文中一共展示了fields.DictField方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_fields
# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import DictField [as 別名]
def get_fields(self):
""" Return the field_mapping needed for serializing the data."""
# Re-implement the logic from the superclass methods, but make sure to handle field and query facets properly.
# https://github.com/edx/course-discovery/blob/master/course_discovery/apps/api/serializers.py#L950
# https://github.com/inonit/drf-haystack/blob/master/drf_haystack/serializers.py#L373
field_data = self.instance.pop('fields', {})
query_data = self.format_query_facet_data(self.instance.pop('queries', {}))
field_mapping = super(DistinctCountsAggregateFacetSearchSerializer, self).get_fields()
field_mapping['fields'] = FacetDictField(
child=FacetListField(child=DistinctCountsFacetFieldSerializer(field_data), required=False)
)
field_mapping['queries'] = DictField(
query_data, child=DistinctCountsQueryFacetFieldSerializer(), required=False
)
if self.serialize_objects:
field_mapping.move_to_end('objects')
self.instance['fields'] = field_data
self.instance['queries'] = query_data
return field_mapping
示例2: get_fields
# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import DictField [as 別名]
def get_fields(self):
query_facet_counts = self.instance.pop('queries', {})
field_mapping = super(BaseHaystackFacetSerializer, self).get_fields()
query_data = self.format_query_facet_data(query_facet_counts)
field_mapping['queries'] = DictField(query_data, child=QueryFacetFieldSerializer(), required=False)
if self.serialize_objects:
field_mapping.move_to_end('objects')
self.instance['queries'] = query_data
return field_mapping