在多个应用中使用streamfield:迁移错误

时间:2016-06-02 20:43:46

标签: wagtail

我的wigtail网站项目分为不同的应用,例如eventpublicationscore.models等。我在core.models中设置了我的流域。

现在,我不仅要在event.models中重用此流域,还要在StreamBlock中重用此流域。

但是,最优雅(干燥)的方法是定义我的流域(子类StreamBlock)只有一次并在我的所有应用中重复使用它?

我的# core/models.py class StoryBlock(StreamBlock): h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") intro = RichTextBlock(icon="pilcrow") paragraph = RichTextBlock(icon="pilcrow") aligned_image = ImageBlock(label="Aligned image") pullquote = PullQuoteBlock() read_on = ReadOnBlock() 的灵感来自wagtaildemo项目中的那个:

# event/models.py
from wagtail.wagtailcore.fields import StreamField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
from core.models import StoryBlock

class EventIndexPage(Page):
    body = StreamField(StoryBlock())

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
    ]

-

makemigrations

但是尝试EventIndexPage更新后的trying to add a non-nullable field 'body' to eventindexpage without a default网页模型会产生警告我core - 但这只发生在非"asdf"上的(stream-)字段上-楷模。

将请求的默认值 - "[]"makemigrations - 传递给migrate构建迁移文件,但以下$ python manage.py migrate ... File "/myproject/venv/lib/python3.5/site-packages/wagtail/wagtailcore/fields.py", line 90, in get_prep_value return json.dumps(self.stream_block.get_prep_value(value), cls=DjangoJSONEncoder) File "/myproject/venv/lib/python3.5/site-packages/wagtail/wagtailcore/blocks/stream_block.py", line 205, in get_prep_value for child in value # child is a BoundBlock instance File "/myproject/venv/lib/python3.5/site-packages/wagtail/wagtailcore/blocks/stream_block.py", line 205, in <listcomp> for child in value # child is a BoundBlock instance AttributeError: 'str' object has no attribute 'block' 失败:

splice()

Full traceback

如果这与我的问题有关:这个项目将被部署到openshift,所以我在使用Python 3时仅限于Django 1.8。很高兴使用wagtail 1.5。

1 个答案:

答案 0 :(得分:4)

gasman在他的comment中出现时,使用""作为迁移的默认值就可以了。