什么 Django 模型字段用于来自 draft.js 的以下 JSON 数据(react-draft-wysiwyg)?

What Django model field to use for the following JSON data from draft.js (react-draft-wysiwyg)?

我的 NextJS 应用程序中有一个 react-draft-wysiwyg 组件,我正在尝试找到一种方法将其存储到我的 Django REST 后端。

这是字符串化的 JSON 我直接从 draft 组件中获得,但我不确定如何组织 django 模型来存储此类数据以及稍后能够发出 PATCH 和 GET 请求。非常感谢任何帮助!

{
  blocks: [
    {
      key: '64o0i',
      text: 'Introduction edited',
      type: 'header-three',
      depth: 0,
      inlineStyleRanges: [],
      entityRanges: [],
      data: {},
    },
    {
      key: 'dcomv',
      text: 'this will be the awesome shit',
      type: 'unstyled',
      depth: 0,
      inlineStyleRanges: [],
      entityRanges: [],
      data: {},
    },
    {
      key: 'edvnc',
      text: 'Body paragraph',
      type: 'header-three',
      depth: 0,
      inlineStyleRanges: [
        { offset: 0, length: 14, style: 'color-rgb(0,0,0)' },
        { offset: 0, length: 14, style: 'bgcolor-rgb(255,255,255)' },
        { offset: 0, length: 14, style: 'fontsize-24' },
        {
          offset: 0,
          length: 14,
          style:
            'fontfamily-ui-sans-serif, system-ui, -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji',
        },
      ],
      entityRanges: [],
      data: {},
    },
    {
      key: 'd3sf7',
      text: 'this will be the awesome shit klasdfj lk;',
      type: 'unstyled',
      depth: 0,
      inlineStyleRanges: [
        { offset: 0, length: 41, style: 'color-rgb(0,0,0)' },
        { offset: 0, length: 41, style: 'bgcolor-rgb(255,255,255)' },
        { offset: 0, length: 41, style: 'fontsize-medium' },
        {
          offset: 0,
          length: 41,
          style:
            'fontfamily-ui-sans-serif, system-ui, -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji',
        },
      ],
      entityRanges: [],
      data: { 'text-align': 'left' },
    },
  ],
  entityMap: {},
};

您可以使用 Django JsonField https://docs.djangoproject.com/en/4.0/ref/models/fields/

def contact_default():
return {"email": "to1@example.com"}

contact_info = JSONField("ContactInfo", default=contact_default)

可以在以下模型中实施:

models.JSONField(default=[])