Blog

Wagtail | Create Page In Migration

Question

After data migration with Page model subclass object creation it doesn’t appear in admin

Answer

# 1 - get your home page
home_page = HomePage.objects.first()  # this will get the first HomePage

# 2 - create a page instance, this is not yet stored in the DB
page = Page(
    title='title',
    slug='slug'
)

# 3 - create the new page as a child of the parent (home), this puts a new page in the DB
home_page.add_child(instance=page)

# 4a - create a revision of the page, assuming you want it published now
page.save_revision()

# 4b - create a revision of the page, without publishing
page.publish()

Resources

Tags: