-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
sandbox/sandbox/apps/home/migrations/0002_create_homepage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
def create_homepage(apps, schema_editor): | ||
# Get models | ||
ContentType = apps.get_model('contenttypes.ContentType') | ||
Page = apps.get_model('wagtailcore.Page') | ||
Site = apps.get_model('wagtailcore.Site') | ||
HomePage = apps.get_model('home.HomePage') | ||
|
||
# Delete the default homepage | ||
# If migration is run multiple times, it may have already been deleted | ||
Page.objects.filter(id=2).delete() | ||
|
||
# Create content type for homepage model | ||
homepage_content_type, __ = ContentType.objects.get_or_create( | ||
model='homepage', app_label='home') | ||
|
||
# Create a new homepage | ||
homepage = HomePage.objects.create( | ||
title="Home", | ||
slug='home', | ||
content_type=homepage_content_type, | ||
path='00010001', | ||
depth=2, | ||
numchild=0, | ||
url_path='/home/', | ||
) | ||
|
||
# Create a site with the new homepage set as the root | ||
Site.objects.create( | ||
hostname='localhost', root_page=homepage, is_default_site=True) | ||
|
||
|
||
def remove_homepage(apps, schema_editor): | ||
# Get models | ||
ContentType = apps.get_model('contenttypes.ContentType') | ||
HomePage = apps.get_model('home.HomePage') | ||
|
||
# Delete the default homepage | ||
# Page and Site objects CASCADE | ||
HomePage.objects.filter(slug='home', depth=2).delete() | ||
|
||
# Delete content type for homepage model | ||
ContentType.objects.filter(model='homepage', app_label='home').delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('home', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_homepage, remove_homepage), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters