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


Python serializers.ListSerializer方法代码示例

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


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

示例1: __init__

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def __init__(self, *args, **kwargs):
            self.child = kwargs.pop('child', copy.deepcopy(self.child))

            self.permission_classes = self.child.permission_classes
            self.check_permission = self.child.check_permission

            self.allow_empty = kwargs.pop('allow_empty', True)

            assert self.child is not None, '`child` is a required argument.'
            assert not inspect.isclass(self.child), '`child` has not been instantiated.'

            # TODO: diagnose/address bad-super-call issue
            # pylint: disable=bad-super-call
            super(ListSerializer, self).__init__(*args, **kwargs)

            self.child.bind(field_name='', parent=self) 
开发者ID:InterSIS,项目名称:django-rest-serializer-field-permissions,代码行数:18,代码来源:fields.py

示例2: __init__

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def __init__(self, serializer, data):
        """Initializes and runs the processor.

        Arguments:
            serializer: a DREST serializer
            data: the serializer's representation
        """

        if isinstance(serializer, ListSerializer):
            serializer = serializer.child
        self.data = {}
        self.seen = defaultdict(set)
        self.plural_name = serializer.get_plural_name()
        self.name = serializer.get_name()

        # process the data, optionally sideloading
        self.process(data)

        # add the primary resource data into the response data
        resource_name = self.name if isinstance(
            data,
            dict
        ) else self.plural_name
        self.data[resource_name] = data 
开发者ID:AltSchool,项目名称:dynamic-rest,代码行数:26,代码来源:processors.py

示例3: to_internal_value

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def to_internal_value(self, data):
        """
        This implements the same relevant logic as ListSerializer except that if one or more items fail validation,
        processing for other items that did not fail will continue.
        """

        if not isinstance(data, list):
            message = self.error_messages['not_a_list'].format(
                input_type=type(data).__name__
            )
            raise serializers.ValidationError({
                api_settings.NON_FIELD_ERRORS_KEY: [message]
            })

        ret = []

        for item in data:
            try:
                validated = self.child.run_validation(item)
            except serializers.ValidationError as exc:
                ret.append(exc.detail)
            else:
                ret.append(validated)

        return ret 
开发者ID:edx,项目名称:edx-enterprise,代码行数:27,代码来源:serializers.py

示例4: __init__

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def __init__(self, serializer):
        """
        :param serializer: DjangoRestFramework Serializer
        """
        if isinstance(serializer, ListSerializer):
            serializer = serializer.child

        self.serializer = serializer
        self.name = self._get_name()

        self.fields = self._collect_fields() 
开发者ID:Arello-Mobile,项目名称:py2swagger,代码行数:13,代码来源:serializer.py

示例5: __init__

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def __init__(self, field, parent, only_fields, include_fields):
        self.field = field
        self.parent = parent
        self.is_many = isinstance(field, serializers.ListSerializer) and isinstance(field.child, serializers.Serializer)
        self.has_context = isinstance(field, serializers.Serializer) or self.is_many
        if self.has_context:
            self.old_context = None
            self.only_fields = self.filter_fields(field.field_name, only_fields)
            self.include_fields = self.filter_fields(field.field_name, include_fields)
            self.on_exit_delete_fields = False
            self.on_exit_delete_include_fields = False
            self.old_fields = None
            self.old_include_fields = None 
开发者ID:HealthByRo,项目名称:drf_tweaks,代码行数:15,代码来源:serializers.py

示例6: __new__

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def __new__(cls, *args, **kwargs):
        """
        Custom constructor that sets the ListSerializer to
        DynamicListSerializer to avoid re-evaluating querysets.

        Addresses DRF 3.1.0 bug:
        https://github.com/tomchristie/django-rest-framework/issues/2704
        """
        meta = getattr(cls, 'Meta', None)
        if not meta:
            meta = type('Meta', (), {})
            cls.Meta = meta

        list_serializer_class = getattr(
            meta,
            'list_serializer_class',
            settings.LIST_SERIALIZER_CLASS or DynamicListSerializer
        )
        if not issubclass(list_serializer_class, DynamicListSerializer):
            list_serializer_class = DynamicListSerializer
        meta.list_serializer_class = list_serializer_class
        return super(
            WithDynamicSerializerMixin, cls
        ).__new__(
            cls, *args, **kwargs
        ) 
开发者ID:AltSchool,项目名称:dynamic-rest,代码行数:28,代码来源:serializers.py

示例7: get_field_info

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def get_field_info(self, field):
        """Adds `related_to` and `nullable` to the metadata response."""
        field_info = OrderedDict()
        for attr in ('required', 'read_only', 'default', 'label'):
            field_info[attr] = getattr(field, attr)
        if field_info['default'] is empty:
            field_info['default'] = None
        if hasattr(field, 'immutable'):
            field_info['immutable'] = field.immutable
        field_info['nullable'] = field.allow_null
        if hasattr(field, 'choices'):
            field_info['choices'] = [
                {
                    'value': choice_value,
                    'display_name': force_text(choice_name, strings_only=True)
                }
                for choice_value, choice_name in field.choices.items()
            ]
        many = False
        if isinstance(field, DynamicRelationField):
            field = field.serializer
        if isinstance(field, ListSerializer):
            field = field.child
            many = True
        if isinstance(field, ModelSerializer):
            type = 'many' if many else 'one'
            field_info['related_to'] = field.get_plural_name()
        else:
            type = self.label_lookup[field]

        field_info['type'] = type
        return field_info 
开发者ID:AltSchool,项目名称:dynamic-rest,代码行数:34,代码来源:metadata.py

示例8: get_related_field

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def get_related_field(field):
    if isinstance(field, ManyRelatedField):
        return field.child_relation

    if isinstance(field, ListSerializer):
        return field.child

    return field 
开发者ID:kevin-brown,项目名称:drf-json-api,代码行数:10,代码来源:utils.py

示例9: is_related_many

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def is_related_many(field):
    if hasattr(field, "many"):
        return field.many

    if isinstance(field, ManyRelatedField):
        return True

    if isinstance(field, ListSerializer):
        return True

    return False 
开发者ID:kevin-brown,项目名称:drf-json-api,代码行数:13,代码来源:utils.py

示例10: data

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def data(self):
        return super(serializers.ListSerializer, self).data 
开发者ID:bkg,项目名称:django-spillway,代码行数:4,代码来源:serializers.py

示例11: data

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def data(self):
        # Note we deliberately return the super of ListSerializer to avoid
        # instantiating a ReturnList, which would force evaluating the generator
        return super(serializers.ListSerializer, self).data


# --------------------------------------------------------
# Document Note Views
# -------------------------------------------------------- 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:11,代码来源:v1.py

示例12: data

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def data(self):
        ret = super(serializers.ListSerializer, self).data
        return ReturnDict(ret, serializer=self) 
开发者ID:GetTogetherComm,项目名称:GetTogether,代码行数:5,代码来源:views.py

示例13: list

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def list(self, request):
        """
        Returns all the beer styles. Do not show suggested
        beer styles by default.
        """
        styles = models.Style.objects.all()
        if request.auth is None:
            styles = styles[:settings.UNAUTHENTICATED_RESULTS_COUNT]

        serializer = rf_serializers.ListSerializer(
            styles,
            child=serializers.SimpleStyleSerializer()
        )
        return Response(serializer.data) 
开发者ID:BrewCenter,项目名称:BrewCenterAPI,代码行数:16,代码来源:styles.py

示例14: list

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def list(self, request):
        """
        Returns all hop types in the system
        """
        serializer = rf_serializers.ListSerializer(
            models.HopType.objects.all() if request.auth is not None else models.HopType.objects.all()[:settings.UNAUTHENTICATED_RESULTS_COUNT],
            child=serializers.HopTypeSerializer()
        )
        return Response(serializer.data) 
开发者ID:BrewCenter,项目名称:BrewCenterAPI,代码行数:11,代码来源:hops.py

示例15: list

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import ListSerializer [as 别名]
def list(self, request):
        """
        Returns all countries in the system.
        """
        serializer = rf_serializers.ListSerializer(
            models.CountryCode.objects.all() if request.auth is not None else models.CountryCode.objects.all()[:settings.UNAUTHENTICATED_RESULTS_COUNT],
            child=serializers.CountryCodeSerializer()
        )
        return Response(serializer.data) 
开发者ID:BrewCenter,项目名称:BrewCenterAPI,代码行数:11,代码来源:countries.py


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