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


Python serializers.BooleanField方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import BooleanField [as 別名]
def __init__(self, *args, **kwargs):
        """
        Start with empty serializer and add fields from both theme schemas
        """
        super().__init__(*args, **kwargs)

        # We're just going to use the v1 theme schema here since v0 is
        # getting deprecated soon
        theme_schema_combined = {
            **theme_schema_v1['properties']
        }
        for key, value in theme_schema_combined.items():
            field_type = None
            if key == 'version':
                field_type = serializers.IntegerField(required=False)
            elif value == ref('flag'):
                field_type = serializers.BooleanField(required=False)
            else:
                field_type = serializers.CharField(
                    max_length=7,
                    required=False,
                    allow_blank=True,
                    # TODO: Add a color validator here
                )
            self.fields[key] = field_type 
開發者ID:open-craft,項目名稱:opencraft,代碼行數:27,代碼來源:serializers.py

示例2: test_boolean_field_error_content

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import BooleanField [as 別名]
def test_boolean_field_error_content(self):
        self.data_set['linenos'] = 'A text instead of a bool'
        s = run_is_valid(SnippetSerializer, data=self.data_set)
        code = settings.FRIENDLY_FIELD_ERRORS['BooleanField']['invalid']
        self.assertEqual(s.errors['errors'][0]['code'], code)
        self.assertEqual(s.errors['errors'][0]['field'], 'linenos') 
開發者ID:FutureMind,項目名稱:drf-friendly-errors,代碼行數:8,代碼來源:test_serializers.py

示例3: test_should_boolean_convert_boolean

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

示例4: generate_fileds

# 需要導入模塊: from rest_framework import serializers [as 別名]
# 或者: from rest_framework.serializers import BooleanField [as 別名]
def generate_fileds(ansible_reference: AnsibleArgumentsReference, ansible_type: str) -> OrderedDict:
    if ansible_type is None:
        return OrderedDict()  # nocv

    fields = OrderedDict()

    for ref, settings in ansible_reference.raw_dict[ansible_type].items():
        if ref in ['help', 'version', ]:
            continue
        ref_type = settings.get('type', None)
        kwargs = dict(help_text=settings.get('help', ''), required=False)
        field = None
        if ref_type is None:
            field = serializers.BooleanField
            kwargs['default'] = False
        elif ref_type == 'int':
            field = serializers.IntegerField
        elif ref_type == 'string' or 'choice':
            field = vst_fields.VSTCharField
            kwargs['allow_blank'] = True

        if ref == 'verbose':
            field = serializers.IntegerField
            kwargs.update(dict(max_value=4, default=0))
        if ref in models.PeriodicTask.HIDDEN_VARS:
            field = vst_fields.SecretFileInString
        if ref == 'inventory':
            kwargs['autocomplete'] = 'Inventory'
            field = InventoryAutoCompletionField

        if field is None:  # nocv
            continue

        if ansible_type == 'module':
            if ref == 'group':
                kwargs['default'] = 'all'

        field_name = ref.replace('-', '_')
        fields[field_name] = field(**kwargs)

    return fields 
開發者ID:vstconsulting,項目名稱:polemarch,代碼行數:43,代碼來源:serializers.py


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