# Generated by Django 3.0.4 on 2020-12-11 17:26
from django.conf import settings
from django.db import migrations


def forwards(apps, schema_editor):
    Community = apps.get_model("community", "Community")
    CommunitySite = apps.get_model("community", "CommunitySite")
    Site = apps.get_model("sites", "Site")
    default_community = Community.objects.first()
    for host in settings.ALLOWED_HOSTS:
        site = Site.objects.filter(domain=host).first()
        if not site:
            site = Site.objects.create(domain=host, name=host.capitalize())
        if default_community:
            CommunitySite.objects.get_or_create(site=site, community=default_community)


class Migration(migrations.Migration):

    dependencies = [
        ("community", "0005_add_community_site"),
    ]

    operations = [migrations.RunPython(forwards, migrations.RunPython.noop)]
