本文整理匯總了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