Unfortunately because models returned by apps.get_model
in migrations aren't the actual class, methods like Page.add
aren't available and we have to do it manually. The most sensitive part being the handling of the path.
As an aside, deleting pages in migration will not update the numchild
of the parent page. Unfortunately, the fixtree
command doesn't play nice within a migration so it will need to be ran separately (or the parent page should manually be updated).
Notes: When not within a migration, a page path could be created with parent_page.get_last_child()._inc_path()
or Page._get_children_path_interval(parent_page.path)[1]
.