简体   繁体   English

如何将旧数据迁移到 django-quill-editor

[英]How to migrate old data to django-quill-editor

I had a textField in my model before.之前我的模型中有一个textField Now I want to upgrade it to a rich text field using Django Quill Editor .现在我想使用Django Quill Editor将其升级为富文本字段。 But I am unable the migrate the old data.但我无法迁移旧数据。

I tried to just copy the text inside the quillfield in a management command but it gives QuillParseError then I looked the databse and figured that the fields are stored like:我试图在管理命令中复制quillfield内的quillfield ,但它给出了QuillParseError然后我查看了数据库并认为这些字段的存储方式如下:

{"delta":"{\"ops\":[{\"insert\":\"text\\n\"}]}","html":"<p>text</p>"}

in the database.在数据库中。 I kept the delta empty and only filled the html.我保持 delta 为空,只填充了 html。 the html appeared in the database but not in the admin. html 出现在数据库中,但不在管理员中。 I then tried to fabricate the ops.然后我尝试制作 ops。 without filling the html and that failed too.没有填写 html 并且失败了。 I can only think of fabricating the whole object but that would be a bit difficult.我只能想到制造整个物体,但这会有点困难。 I was wondering if there is any sane way to migrate html/text data to quillfield or any other richtext editor.我想知道是否有任何理智的方法可以将 html/text 数据迁移到 quillfield 或任何其他富文本编辑器。

我已将此值添加为旧模型中新字段的默认值,并且它起作用了:

default='{"delta":{"ops":[{"insert":"test"}]},"html":"<p>test</p>"}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM