Programatically setting up Django with Wagtail


Okay so you have installed wagtail and you are starting from scratch with a drop database/create database and you have just run migrate. After that you need to go through the pain of creating a superuser, logging in setting up the site root page etc etc. In reality I just want to have a script I can run that can set up everything that I need to develop the site.

Here is a management command that I run to get going:

from import BaseCommand
from wagtail.core.models import Page, Site

from home.models import HomePage
from django.contrib.auth import get_user_model

User = get_user_model()

class Command(BaseCommand):
    help = "Gets the site up and running for Devs"

    def handle(self, *args, **options):

        # create site
        parent = Page.objects.get(url_path="/")
        home_page = HomePage(title="home", body="home", slug="home")
            hostname="", is_default_site=True, root_page=home_page
        User.objects.create_superuser("admin", "", "admin")

Let me know if this helps on twitter @chriswedgwood. As your site grows in complexity this will grow