Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of json Field coding in django model postgres

Shulou Source: shulou.com Published: 2022-06-03 16:46:21 10月05日 Update

This article mainly shows you the "example analysis of json field coding problems in django model postgres", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and study the "example analysis of json field coding problems in django model postgres".

The encoder of the json field of django model cannot effectively encode data types such as uuid,datetime. When an object of this type is directly stored in the json field to throw a coding exception, you can specify the json encoder through the encoder parameter of the JSONField field. Here, the JSONEncoder of django rest framework is used directly.

From django.contrib.postgres.fields import JSONFieldfrom rest_framework.utils.encoders import JSONEncoder# django.contrib.postgres.fields.jsonb.JSONField (default=dict, encoder=rest_framework.utils.encoders.JSONEncoder) detail = JSONField (default=dict, encoder=JSONEncoder, help_text=u' details') these are all the contents of this article entitled "sample Analysis of json Field coding problems in django model postgres". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Coding fields examples questions analysis content articles types encoders learning help validity parameters can be passed objects data easy to understand more organization knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Docker MySQL Microsoft Linux