0

with below customized Page model,

class PostDetail(Page):
    body = RichTextField(blank=True)

    search_fields = Page.search_fields + [
        index.SearchField("body"),
    ]

    content_panels = Page.content_panels + [
        FieldPanel("title"),
        FieldPanel("body"),
    ]

I did not add title = models.Char() because PostDetail will inherit all attributes (including title) from wagtail built-in Page model.

But when I tried to add a Post Detail page, I saw duplicated title fields. why is that? enter image description here

Yan Tian
  • 377
  • 3
  • 11

1 Answers1

1

FieldPanel("title") is already defined in Page.content_panels, so Page.content_panels + [FieldPanel("title")] defines it twice.

gasman
  • 23,691
  • 1
  • 38
  • 56
  • according to source code, https://github.com/wagtail/wagtail/blob/main/wagtail/core/models/__init__.py, `content_panels = []` is configured in `class Page()`. So I expected `Page.content_panels` to be empty? – Yan Tian Jul 22 '21 at 09:22
  • They get set up in https://github.com/wagtail/wagtail/blob/ca15f2d991d4d35f1dfc194bfa81c99504574e15/wagtail/admin/edit_handlers.py#L910-L938 - it can't be done in the wagtail.core.models module because that would create a circular dependency between the wagtail.core and wagtail.admin apps. – gasman Jul 22 '21 at 10:06