0002_initial_data.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. def initial_data(apps, schema_editor):
  6. ContentType = apps.get_model('contenttypes.ContentType')
  7. Page = apps.get_model('wagtailcore.Page')
  8. Site = apps.get_model('wagtailcore.Site')
  9. WebPage = apps.get_model('website.WebPage')
  10. # Create page content type
  11. webpage_content_type, created = ContentType.objects.get_or_create(
  12. model='webpage',
  13. app_label='website',
  14. )
  15. # Delete the default home page generated by wagtail,
  16. # and replace it with a more useful page type.
  17. curr_homepage = Page.objects.filter(slug='home').delete()
  18. homepage = WebPage.objects.create(
  19. title = "Home",
  20. slug='home',
  21. custom_template='coderedcms/pages/home_page.html',
  22. content_type=webpage_content_type,
  23. path='00010001',
  24. depth=2,
  25. numchild=0,
  26. url_path='/home/',
  27. )
  28. # Create a new default site
  29. Site.objects.create(
  30. hostname='localhost',
  31. site_name='My Company Inc.',
  32. root_page_id=homepage.id,
  33. is_default_site=True
  34. )
  35. class Migration(migrations.Migration):
  36. dependencies = [
  37. ('coderedcms', '0001_initial'),
  38. ('wagtailcore', '0002_initial_data'),
  39. ('website', '0001_initial'),
  40. ]
  41. operations = [
  42. migrations.RunPython(initial_data),
  43. ]