# Generated by Django 2.2.7 on 2020-01-28 17:54

from django.db import migrations, models
import django.db.models.deletion


def delete_unused_partners(apps, schema_editor):
    PartnerToEstablishment = apps.get_model('partner', 'PartnerToEstablishment')
    Partner = apps.get_model('partner', 'Partner')
    ids_to_preserve = []
    for p_t_e in PartnerToEstablishment.objects.all():
        ids_to_preserve.append(p_t_e.partner.pk)
    Partner.objects.exclude(id__in=ids_to_preserve).delete()


class Migration(migrations.Migration):
    dependencies = [
        ('location', '0037_address_district_name'),
        ('establishment', '0083_establishment_instagram'),
        ('partner', '0004_auto_20200128_1746'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='partner',
            name='establishments',
        ),
        migrations.AddField(
            model_name='partner',
            name='country',
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.SET_NULL,
                                    to='location.Country'),
        ),
        migrations.RemoveField(
            model_name='partner',
            name='establishment',
        ),
        migrations.AddField(
            model_name='partner',
            name='establishment',
            field=models.ManyToManyField(related_name='partners', through='partner.PartnerToEstablishment',
                                         to='establishment.Establishment', verbose_name='Establishments'),
        ),
        migrations.RunPython(delete_unused_partners, migrations.RunPython.noop, atomic=True)
    ]
