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