问题描述
使用以下定制的 Page
模型,
class PostDetail(Page):
body = RichTextField(blank=True)
search_fields = Page.search_fields + [
index.SearchField("body"),]
content_panels = Page.content_panels + [
FieldPanel("title"),FieldPanel("body"),]
我没有添加 title = models.Char()
因为 PostDetail
将从 wagtail 内置 title
模型继承所有属性(包括 Page
)。
但是当我尝试添加 Post Detail
页面时,我看到重复的 title
字段。这是为什么?
解决方法
FieldPanel("title")
已经在 Page.content_panels
中定义,所以 Page.content_panels + [FieldPanel("title")]
定义了两次。