本文整理汇总了Python中rest_framework.serializers.JSONField方法的典型用法代码示例。如果您正苦于以下问题:Python serializers.JSONField方法的具体用法?Python serializers.JSONField怎么用?Python serializers.JSONField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.serializers
的用法示例。
在下文中一共展示了serializers.JSONField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import JSONField [as 别名]
def validate(self, data):
data = super().validate(data)
errors = {}
for name, field in self.fields.items():
if type(field) is serializers.CharField:
value = data.get(name)
if value:
value = value.strip()
data[name] = value
valid = sanitize_string(value)
elif type(field) is serializers.JSONField:
value = data.get(name, {}) or {}
valid = all(sanitize_string(value[k]) for k in value)
if not valid:
errors[name] = [SANITIZE_ERROR]
if errors:
raise serializers.ValidationError(errors)
return data
示例2: fallback_schema_from_field
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import JSONField [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
)
示例3: test_should_json_convert_jsonstring
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import JSONField [as 别名]
def test_should_json_convert_jsonstring():
assert_conversion(serializers.JSONField, graphene.types.json.JSONString)