I followed Official Wagtail Docs to integrate freshly installed Wagtail into existing Django project.
I added customized HomePage
class in existing Django's models.py
.
# myDjangoProject/models.py
class HomePage(Page):
template = "homepage.html"
content = RichTextField()
content_panels = Page.content_panels + [
FieldPanel("content")
]
Q1: In above screenshot, Why system default page Welcome to Wagtail
is of Page
TYPE, while newly created New Page
is of Home page
TYPE automatically ?
Q2: In above screenshot, Why Newly-created child page under system default page Welcome to Wagtail
is of Home page
surprisingly without any manual configuration ?
Q3: In above screenshot, why all newly-created pages automatically (no manual configuration required) inherited from my customized HomePage
class in MyDjangoProject/models.py
? How is this reflected on source code level ?
The Page
class is the base class of all page types in Wagtail, but normally it wouldn't be desirable to let users create pages that are of the type Page
rather than something more specific, because there's no way to add new content fields to it. For this reason, the is_creatable
attribute is set to false on Page
, which means that new pages of that type can't be created through the admin interface. (This attribute is not inherited by subclasses, so any new page types you create will be is_creatable = True
by default.)
The initial "Welcome" page is created as part of the migrations in the wagtail.core
app. At this point, Page
is the only page type that exists (since your HomePage model hasn't been defined yet), so that's the one Wagtail uses. It might seem a bit weird that the default page is not one that you can create yourself through the admin, but there's no real alternative (other than not providing a default page at all, which would make it harder for developers to see if their installation has worked).
(When setting up a brand new Wagtail project through wagtail start
, the project template includes migrations to replace the initial Page
instance with an instance of the supplied HomePage
model, so in this case it's less confusing.)
After you defined your HomePage
model, this became the only page type with is_creatable = True
, and so the admin interface automatically selects this page type on adding a new page. When you add another page model alongside HomePage, you'll find that it prompts you to select a page type.