當前位置: 首頁>>代碼示例>>Python>>正文


Python fields.DictField方法代碼示例

本文整理匯總了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 
開發者ID:edx,項目名稱:course-discovery,代碼行數:25,代碼來源:serializers.py

示例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 
開發者ID:edx,項目名稱:course-discovery,代碼行數:17,代碼來源:serializers.py


注:本文中的rest_framework.fields.DictField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。