0002_initial_data.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.core.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('website.WebPage')
  11. # Create page content type
  12. webpage_content_type, created = ContentType.objects.get_or_create(
  13. model='webpage',
  14. app_label='website',
  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='coderedcms/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='localhost',
  33. site_name='My Company Inc.',
  34. root_page_id=homepage.id,
  35. is_default_site=True
  36. )
  37. class Migration(migrations.Migration):
  38. dependencies = [
  39. ('coderedcms', '0001_initial'),
  40. ('wagtailcore', '0057_page_locale_fields_notnull'),
  41. ('website', '0001_initial'),
  42. ]
  43. operations = [
  44. migrations.RunPython(initial_data),
  45. ]