# Generated by Django 5.0.8 on 2024-12-11 13:24

from django.db import migrations, models


def forwards_func(apps, schema_editor):
    AccessRestrictionGroup = apps.get_model('mapdata', 'AccessRestrictionGroup')
    for group in AccessRestrictionGroup.objects.prefetch_related("accessrestrictions").all():
        group.members.set(group.accessrestrictions.all())


def backwards_func(apps, schema_editor):
    AccessRestrictionGroup = apps.get_model('mapdata', 'AccessRestrictionGroup')
    for group in AccessRestrictionGroup.objects.prefetch_related("members").all():
        group.accessrestrictions.set(group.members.all())


class Migration(migrations.Migration):

    dependencies = [
        ('mapdata', '0113_locationgroup_can_report_mistake'),
    ]

    operations = [
        migrations.AddField(
            model_name='accessrestrictiongroup',
            name='members',
            field=models.ManyToManyField(blank=True, to='mapdata.accessrestriction', verbose_name='Access Restrictions'),
        ),
        migrations.RunPython(forwards_func, backwards_func),
        migrations.RemoveField(
            model_name='accessrestriction',
            name='groups',
        ),
        migrations.AlterField(
            model_name='accessrestrictiongroup',
            name='members',
            field=models.ManyToManyField(blank=True, related_name='groups', to='mapdata.accessrestriction',
                                         verbose_name='Access Restrictions'),
        ),
    ]
