from __future__ import unicode_literals

from django.db import migrations, models


def set_homepage(apps, schema_editor):
    Site = apps.get_model('wagtailcore.Site')
    HomePage = apps.get_model("core", "HomePage")
    homepage = HomePage.objects.get(slug="home")

    # Create default site
    Site.objects.create(
        hostname='localhost',
        root_page_id=homepage.id,
        is_default_site=True
    )

class Migration(migrations.Migration):

    dependencies = [
        ('core', '0002_create_home_page'),
    ]

    operations = [
        migrations.RunPython(set_homepage),
    ]

from __future__ import unicode_literals

from django.db import migrations, models


def set_homepage(apps, schema_editor):
    Site = apps.get_model('wagtailcore.Site')
    HomePage = apps.get_model("core", "HomePage")
    homepage = HomePage.objects.get(slug="home")

    Site.objects.filter(hostname='localhost').delete()

    # Create default site
    Site.objects.get_or_create(
        hostname='localhost',
        root_page_id=homepage.id,
        is_default_site=True
    )

class Migration(migrations.Migration):

    dependencies = [
        ('core', '0002_create_home_page'),
    ]

    operations = [
        migrations.RunPython(set_homepage),
    ]

Delete existing localhost entry for site.
Delete existing localhost entry for site.

  from __future__ import unicode_literals
  
  from django.db import migrations, models
  
  
  def set_homepage(apps, schema_editor):
      Site = apps.get_model('wagtailcore.Site')
      HomePage = apps.get_model("core", "HomePage")
      homepage = HomePage.objects.get(slug="home")
  
+     Site.objects.filter(hostname='localhost').delete()
+ 
      # Create default site
-     Site.objects.create(
+     Site.objects.get_or_create(
          hostname='localhost',
          root_page_id=homepage.id,
          is_default_site=True
      )
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('core', '0002_create_home_page'),
      ]
  
      operations = [
          migrations.RunPython(set_homepage),
      ]
  
Delete existing localhost entry for site.
## Code Before:
from __future__ import unicode_literals

from django.db import migrations, models


def set_homepage(apps, schema_editor):
    Site = apps.get_model('wagtailcore.Site')
    HomePage = apps.get_model("core", "HomePage")
    homepage = HomePage.objects.get(slug="home")

    # Create default site
    Site.objects.create(
        hostname='localhost',
        root_page_id=homepage.id,
        is_default_site=True
    )

class Migration(migrations.Migration):

    dependencies = [
        ('core', '0002_create_home_page'),
    ]

    operations = [
        migrations.RunPython(set_homepage),
    ]

## Instruction:
Delete existing localhost entry for site.
## Code After:
from __future__ import unicode_literals

from django.db import migrations, models


def set_homepage(apps, schema_editor):
    Site = apps.get_model('wagtailcore.Site')
    HomePage = apps.get_model("core", "HomePage")
    homepage = HomePage.objects.get(slug="home")

    Site.objects.filter(hostname='localhost').delete()

    # Create default site
    Site.objects.get_or_create(
        hostname='localhost',
        root_page_id=homepage.id,
        is_default_site=True
    )

class Migration(migrations.Migration):

    dependencies = [
        ('core', '0002_create_home_page'),
    ]

    operations = [
        migrations.RunPython(set_homepage),
    ]
