我有一个基于w的CMS,最近以更明智的方式重新编写了它。我编写了一个脚本,将旧内容迁移到基于wagtail 2.3(旧版本在wagtail 1.11上)的新版本。我已经编写了迁移脚本(用于重新构造各种外键等),并且所有内容均已填充,并且似乎可以正常工作,除了StreamFields的呈现方式。
令人沮丧的是,当我切换回v2的测试数据库时,此方法工作正常(呈现了内容)-我一直在数据库中搜索两行之间的差异(在wagtailcore_page或blog_blogpostpage中),并且看不到任何内容区别。 w提取StreamField内容的方式中显然缺少某些东西,有人可以启发我有关迁移中可能错过的内容吗?非常感谢!
models.py
class BlogPostPage(Page): # Individual blog post
template = 'blog/post_page.html'
parent_page_types = ['blog.BlogIndexPage']
show_in_menus_default = True
author = models.ForeignKey(
User, on_delete=models.PROTECT, default=1,
)
description = models.CharField(
max_length=300, blank=False,
help_text="Add a brief (max 300 characters) description for this blog post."
)
date = models.DateField(
"Post date",
help_text="This date may be displayed on the blog post. "
"It is not used to schedule posts to go live at a later date."
)
body = StreamField([
('heading', blocks.CharBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('embed', EmbedBlock()),
('image', ImageChooserBlock(classname='img-responsive')),
('code', CodeBlock(label='Code')),
('table', TableBlock(label='Table'))
], help_text="Create content by adding new blocks.")
表blog_blogpostpage条目:
"page_ptr_id","description","date","body","author_id"
23,"Now including Blog!","2018-12-06","[{""type"": ""paragraph"", ""value"": ""<p>Since the first release we've made some improvements and upgrades...</p>"", ""id"": ""25fe32be-2090-42dd-8e3e-4df53c494227""}]",15
migration_script.sh
INSERT INTO "public"."wagtailcore_page"("path","depth","numchild","title","slug","live","has_unpublished_changes","url_path","seo_title","show_in_menus","search_description","go_live_at","expire_at","expired","content_type_id","owner_id","locked","latest_revision_created_at","first_published_at","live_revision_id","last_published_at","draft_title")
VALUES
(E'00010002000O0001',4,0,E'Release: version 2',E'release-version-2',TRUE,FALSE,E'/home/blog/release-version-2/',E'',TRUE,E'',NULL,NULL,FALSE,6,15,FALSE,E'2018-12-06 16:58:10.897348+08',E'2018-12-06 16:58:10.926032+08',NULL,E'2018-12-06 16:58:10.926032+08',E'Release: version 2');
INSERT INTO "public"."blog_blogpostpage"("page_ptr_id","description","date","body","author_id")
VALUES
((SELECT id FROM wagtailcore_page WHERE path='00010002000O0001'),E'Now including Blog!',E'2018-12-06',E'[{"type": "paragraph", "value": "<p>Since the first release we've made some improvements and upgrades...</p>", "id": "25fe32be-2090-42dd-8e3e-4df53c494227"}]',15);
template.html
{% include_block page.body %}
^^^ page.body字段未显示任何内容,但呈现了描述,日期和作者。
答案 0 :(得分:1)
您的数据迁移创建了无效的JSON:
[{""type"": ""paragraph"", ""value"": ""<p>S ...
应使用单引号:
[{"type": "paragraph", "value": "<p>S ...