load_initial_data.py 1006 B

123456789101112131415161718192021222324
  1. import os
  2. from django.conf import settings
  3. from django.core.management.base import BaseCommand
  4. from django.core.management import call_command
  5. from wagtail.wagtailcore.models import Site, Page
  6. class Command(BaseCommand):
  7. def handle(self, **options):
  8. fixtures_dir = os.path.join(settings.BASE_DIR, 'base', 'fixtures')
  9. fixture_file = os.path.join(fixtures_dir, 'bakerydemo.json')
  10. call_command('loaddata', fixture_file, verbosity=0)
  11. # Wagtail creates default Site and Page instances during install, but we already have
  12. # them in the data load. Remove the auto-generated ones.
  13. if Site.objects.filter(hostname='localhost').exists():
  14. Site.objects.get(hostname='localhost').delete()
  15. if Page.objects.filter(title='Welcome to your new Wagtail site!').exists():
  16. Page.objects.get(title='Welcome to your new Wagtail site!').delete()
  17. print("Awesome. Your data is loaded! The bakery's doors are almost ready to open...")