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


Python serializers.DecimalField方法代碼示例

本文整理匯總了Python中rest_framework.serializers.DecimalField方法的典型用法代碼示例。如果您正苦於以下問題:Python serializers.DecimalField方法的具體用法?Python serializers.DecimalField怎麽用?Python serializers.DecimalField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.serializers的用法示例。


在下文中一共展示了serializers.DecimalField方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_should_decimal_convert_float

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DecimalField [as 別名]
def test_should_decimal_convert_float():
    assert_conversion(
        serializers.DecimalField, graphene.Float, max_digits=4, decimal_places=2
    ) 
開發者ID:graphql-python,項目名稱:graphene-django,代碼行數:6,代碼來源:test_field_converter.py

示例2: get_price

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DecimalField [as 別名]
def get_price(self, product):
        info = self._get_info(product)
        if info.availability.is_available_to_buy:
            return serializers.DecimalField(max_digits=10, decimal_places=2).to_representation(info.price.excl_tax)
        return None 
開發者ID:edx,項目名稱:ecommerce,代碼行數:7,代碼來源:serializers.py

示例3: build_standard_field

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import DecimalField [as 別名]
def build_standard_field(self, field_name, model_field):
        """
        Create regular model fields.
        """
        field_mapping = ClassLookupDict(self.serializer_field_mapping)

        field_class = field_mapping[model_field]
        field_kwargs = self.get_field_kwargs(field_name, model_field)
        if 'choices' in field_kwargs:
            # Fields with choices get coerced into `ChoiceField`
            # instead of using their regular typed field.
            field_class = self.serializer_choice_field
            # Some model fields may introduce kwargs that would not be valid
            # for the choice field. We need to strip these out.
            # Eg. models.DecimalField(max_digits=3, decimal_places=1,
            #                         choices=DECIMAL_CHOICES)

            valid_kwargs = {
                'read_only', 'write_only',
                'required', 'default', 'initial', 'source',
                'label', 'help_text', 'style',
                'error_messages', 'validators', 'allow_null', 'allow_blank',
                'choices'
            }
            for key in list(field_kwargs.keys()):
                if key not in valid_kwargs:
                    field_kwargs.pop(key)

        if not issubclass(field_class, ModelField):
            # `model_field` is only valid for the fallback case of
            # `ModelField`, which is used when no other typed field
            # matched to the model field.
            field_kwargs.pop('model_field', None)

        if not issubclass(field_class, CharField) and not \
                issubclass(field_class, ChoiceField):
            # `allow_blank` is only valid for textual fields.
            field_kwargs.pop('allow_blank', None)

        if postgres_fields and isinstance(model_field,
                                          postgres_fields.ArrayField):
            # Populate the `child` argument on `ListField` instances generated
            # for the PostgrSQL specfic `ArrayField`.
            child_model_field = model_field.base_field
            child_field_class, child_field_kwargs = self.build_standard_field(
                'child', child_model_field
            )
            field_kwargs['child'] = child_field_class(**child_field_kwargs)

        return field_class, field_kwargs 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:52,代碼來源:serializers.py


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