【问题标题】:how to use dictionary field in Django?如何在 Django 中使用字典字段?
【发布时间】:2020-11-24 07:50:38
【问题描述】:

我需要在 Django 模型上使用字典字段。

例如,在数据上

name = Kim, user_id = 12902938291, dictionary = {'yo' : 'drop', 'the': 'beat'}

我知道型号serialization,但它不能满足我的要求。

如何在 Django 中使用字典字段?

【问题讨论】:

    标签: python django dictionary


    【解决方案1】:

    另一个干净快速的解决方案可以在这里找到:https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.JSONField

    为方便起见,我复制了简单的说明。

    用法

    from django.db import models
    
    class MyModel(models.Model):
        json = JSONField()
    

    【讨论】:

    猜你喜欢
    • 2011-07-27
    • 2017-08-26
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 2013-01-15
    • 2013-03-07
    • 2010-11-22
    • 2016-11-28
    相关资源
    最近更新 更多