本文整理汇总了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
示例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')
示例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)
示例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