當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。