当前位置: 首页>>代码示例>>Python>>正文


Python serializers.py方法代码示例

本文整理汇总了Python中rest_framework.serializers.py方法的典型用法代码示例。如果您正苦于以下问题:Python serializers.py方法的具体用法?Python serializers.py怎么用?Python serializers.py使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rest_framework.serializers的用法示例。


在下文中一共展示了serializers.py方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_fields

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import py [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: format_query_facet_data

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import py [as 别名]
def format_query_facet_data(self, query_facet_counts):
        """ Format and return the query facet data so that it may be properly serialized."""
        # Re-implement the logic from the superclass method, but make sure to handle changes to the raw query facet
        # data and extract the distinct counts.
        # https://github.com/edx/course-discovery/blob/master/course_discovery/apps/api/serializers.py#L966
        query_data = {}
        for field, options in getattr(self.Meta, 'field_queries', {}).items():
            # The query facet data is expected to be formatted as a dictionary with fields mapping to a two-tuple
            # containing count and distinct count.
            count, distinct_count = query_facet_counts.get(field, (0, 0))
            if count:
                query_data[field] = {
                    'field': field,
                    'options': options,
                    'count': count,
                    'distinct_count': distinct_count,
                }
        return query_data 
开发者ID:edx,项目名称:course-discovery,代码行数:20,代码来源:serializers.py

示例3: get_distinct_count

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import py [as 别名]
def get_distinct_count(self, instance):
        """ Return the distinct count for this facet."""
        # The instance is expected to be formatted as a three tuple containing the field name, normal count and
        # distinct count. This is consistent with the superclass implementation here:
        # https://github.com/inonit/drf-haystack/blob/master/drf_haystack/serializers.py#L321
        count = instance[2]
        return serializers.IntegerField(read_only=True).to_representation(count) 
开发者ID:edx,项目名称:course-discovery,代码行数:9,代码来源:serializers.py


注:本文中的rest_framework.serializers.py方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。