浅谈django model postgres的json字段编码问题
djangomodel的json字段的编码器不能有效编码诸如uuid,datetime等数据类型,当直接存储此类型的对象到json字段中为抛出编码异常,这时可以通过JSONField字段的encoder参数指定json编码器,这里直接使用djangorestframework的JSONEncoder
fromdjango.contrib.postgres.fieldsimportJSONField fromrest_framework.utils.encodersimportJSONEncoder #django.contrib.postgres.fields.jsonb.JSONField(default=dict,encoder=rest_framework.utils.encoders.JSONEncoder) detail=JSONField(default=dict,encoder=JSONEncoder,help_text=u'详情')
以上这篇浅谈djangomodelpostgres的json字段编码问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。