0002_initial.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django import VERSION as DJANGO_VERSION
  4. from django.db import migrations
  5. from wagtail.models import Locale
  6. def initial_data(apps, schema_editor):
  7. ContentType = apps.get_model('contenttypes.ContentType')
  8. Page = apps.get_model('wagtailcore.Page')
  9. Site = apps.get_model('wagtailcore.Site')
  10. WebPage = apps.get_model('testapp.WebPage')
  11. # Create page content type
  12. webpage_content_type, created = ContentType.objects.get_or_create(
  13. model='webpage',
  14. app_label='testapp',
  15. )
  16. # Delete the default home page generated by wagtail,
  17. # and replace it with a more useful page type.
  18. curr_homepage = Page.objects.filter(slug='home').delete()
  19. homepage = WebPage.objects.create(
  20. title = "Home",
  21. slug='home',
  22. custom_template='wagtailcrx/pages/home_page.html',
  23. content_type=webpage_content_type,
  24. path='00010001',
  25. depth=2,
  26. numchild=0,
  27. url_path='/home/',
  28. locale_id=Locale.get_default().id,
  29. )
  30. # Create a new default site
  31. Site.objects.create(
  32. hostname='',
  33. site_name='Test Site',
  34. root_page_id=homepage.id,
  35. is_default_site=True
  36. )
  37. class Migration(migrations.Migration):
  38. dependencies = [
  39. ('testapp', '0001_initial'),
  40. ('wagtailcore', '0002_initial_data'),
  41. ]
  42. operations = [
  43. migrations.RunPython(initial_data),
  44. ]