django 序列化器 dictfield 与 jsonfield

问题描述 投票:0回答:0

我在 postgres 中有一个类型为

custom_property
的专栏
jsonb

我需要验证此列的有效负载。

payload:

{
    "description": "test description3",
    "custom_property": {
        "access": "Yes"
    }
}

我有一个序列化程序:

class MySerializer(serializers.Serializer):
    description = serializers.CharField(required=False, max_length=500)
    custom_property = serializers.DictField(required=False)

我应该为这个专栏使用

DictField
还是
JSONField

看来在这两种情况下,都需要先用

json.dumps()
格式化为json字符串。

python json django dictionary django-serializer
© www.soinside.com 2019 - 2024. All rights reserved.