本文整理汇总了Python中rest_framework.fields.Field方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Field方法的具体用法?Python fields.Field怎么用?Python fields.Field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.fields
的用法示例。
在下文中一共展示了fields.Field方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import Field [as 别名]
def __init__(
self,
requires=None,
deferred=None,
field_type=None,
immutable=False,
**kwargs
):
"""
Arguments:
deferred: Whether or not this field is deferred.
Deferred fields are not included in the response,
unless explicitly requested.
field_type: Field data type, if not inferrable from model.
requires: List of fields that this field depends on.
Processed by the view layer during queryset build time.
"""
self.requires = requires
self.deferred = deferred
self.field_type = field_type
self.immutable = immutable
self.kwargs = kwargs
super(DynamicField, self).__init__(**kwargs)
示例2: mongo_field_repr
# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import Field [as 别名]
def mongo_field_repr(value):
# mimic django models.Field.__repr__
path = '%s.%s' % (value.__class__.__module__, value.__class__.__name__)
name = getattr(value, 'name', None)
if name is not None:
return '<%s: %s>' % (path, name)
return '<%s>' % path
示例3: smart_repr
# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import Field [as 别名]
def smart_repr(value):
if isinstance(value, QuerySet):
return manager_repr(value)
if isinstance(value, BaseField):
return mongo_field_repr(value)
if isinstance(value, BaseDocument):
return mongo_field_repr(value)
if isinstance(value, Field):
return field_repr(value)
value = repr(value)
# Representations like u'help text'
# should simply be presented as 'help text'
value = uni_lit_re.sub("'\\1'", value)
# Representations like
# <django.core.validators.RegexValidator object at 0x1047af050>
# Should be presented as
# <django.core.validators.RegexValidator object>
value = re.sub(' at 0x[0-9a-f]{4,32}>', '>', value)
return value
示例4: _get_validator
# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import Field [as 别名]
def _get_validator(self) -> Field:
return ValidatorFactory.make(self.param.annotation, self.settings)