本文整理汇总了Python中rest_framework.serializers.DictField方法的典型用法代码示例。如果您正苦于以下问题:Python serializers.DictField方法的具体用法?Python serializers.DictField怎么用?Python serializers.DictField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.serializers
的用法示例。
在下文中一共展示了serializers.DictField方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _writable_fields
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import DictField [as 别名]
def _writable_fields(self) -> List:
writable_fields = super(_SignalSerializer, self)._writable_fields
fields = []
attrs = [
'field_name', 'source_attrs', 'source',
'read_only', 'required', 'write_only', 'default'
]
for field in writable_fields:
if not isinstance(field, DataSerializer):
fields.append(field)
continue
field_object = serializers.DictField()
for attr in attrs:
setattr(field_object, attr, getattr(field, attr, None))
fields.append(field_object)
return fields
示例2: get_fields
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import DictField [as 别名]
def get_fields(self):
query_facet_counts = self.instance.pop('queries', {})
field_mapping = super(BaseHaystackFacetSerializer, self).get_fields()
query_data = self.format_query_facet_data(query_facet_counts)
field_mapping['queries'] = DictField(query_data, child=QueryFacetFieldSerializer(), required=False)
if self.serialize_objects:
field_mapping.move_to_end('objects')
self.instance['queries'] = query_data
return field_mapping
示例3: fallback_schema_from_field
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import DictField [as 别名]
def fallback_schema_from_field(self, field):
""" Fallback schema for field that isn't inspected properly by DRF
and probably won't land in upstream canon due to its hacky nature only for doc purposes
"""
title = force_text(field.label) if field.label else ''
description = force_text(field.help_text) if field.help_text else ''
# since we can't really inspect dictfield and jsonfield, at least display object as type
# instead of string
if isinstance(field, (serializers.DictField, serializers.JSONField)):
return coreschema.Object(
properties={},
title=title,
description=description
)
示例4: test_should_dict_convert_dict
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import DictField [as 别名]
def test_should_dict_convert_dict():
assert_conversion(serializers.DictField, DictType)
示例5: __init__
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import DictField [as 别名]
def __init__(self, *args, **kwargs):
self.allow_empty = kwargs.pop('allow_empty', True)
super(DictField, self).__init__(*args, **kwargs)