当前位置: 首页>>代码示例>>Python>>正文


Python serializers.SlugRelatedField方法代码示例

本文整理汇总了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) 
开发者ID:product-definition-center,项目名称:product-definition-center,代码行数:14,代码来源:serializers.py

示例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


注:本文中的rest_framework.serializers.SlugRelatedField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。