我的wigtail网站项目分为不同的应用,例如event
,publications
,core.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()
如果这与我的问题有关:这个项目将被部署到openshift,所以我在使用Python 3时仅限于Django 1.8。很高兴使用wagtail 1.5。