本文整理汇总了Python中rest_framework.serializers.SlugRelatedField方法的典型用法代码示例。如果您正苦于以下问题:Python serializers.SlugRelatedField方法的具体用法?Python serializers.SlugRelatedField怎么用?Python serializers.SlugRelatedField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.serializers
的用法示例。
在下文中一共展示了serializers.SlugRelatedField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: allowed_push_targets_field
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import SlugRelatedField [as 别名]
def allowed_push_targets_field(parent_key):
if parent_key:
help_text = 'Allowed push targets (subset from parent %s)' % parent_key
else:
help_text = 'Allowed push targets'
return serializers.SlugRelatedField(
many=True,
slug_field='name',
queryset=PushTarget.objects.all(),
default=[],
help_text=help_text)
示例2: _get_field_type
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import SlugRelatedField [as 别名]
def _get_field_type(serializer, field_name, field, include_read_only):
"""
Try to describe a field type.
"""
if not include_read_only and hasattr(field, 'writable_doc_format'):
return _get_type_from_docstring(field.writable_doc_format)
if hasattr(field, 'doc_format'):
return _get_type_from_docstring(field.doc_format)
if isinstance(field, (relations.ManyRelatedField, serializers.ListSerializer)):
# Many field, recurse on child and make it a list
if isinstance(field, relations.ManyRelatedField):
field = field.child_relation
else:
field = field.child
return [_get_field_type(serializer, field_name, field, include_read_only)]
if field.__class__.__name__ in _SERIALIZER_DEFS:
return _SERIALIZER_DEFS[field.__class__.__name__]
if isinstance(field, serializers.SlugRelatedField):
return _get_details_for_slug(serializer, field_name, field)
if isinstance(field, serializers.SerializerMethodField):
# For method fields try to use docstring of the method.
method_name = field.method_name or 'get_{field_name}'.format(field_name=field_name)
method = getattr(serializer, method_name, None)
if method:
docstring = getattr(method, '__doc__')
return _get_type_from_docstring(docstring, docstring or 'method')
if isinstance(field, serializers.BaseSerializer):
return describe_serializer(field, include_read_only)
logger = logging.getLogger(__name__)
logger.error('Undocumented field %s' % field)
return 'UNKNOWN'
开发者ID:product-definition-center,项目名称:product-definition-center,代码行数:40,代码来源:renderers_serializers.py