# Generated by Django 2.1.5 on 2019-03-04 17:26

from django.db import migrations
from django.db.models import Count


def make_checkins_unique(apps, se):
    Checkin = apps.get_model('pretixbase', 'Checkin')
    for d in Checkin.objects.order_by().values('list_id', 'position_id').annotate(c=Count('id')).filter(c__gt=1):
        for c in Checkin.objects.filter(list_id=d['list_id'], position_id=d['position_id'])[:d['c'] - 1]:
            c.delete()


class Migration(migrations.Migration):
    dependencies = [
        ('pretixbase', '0111_auto_20190219_0949'),
    ]

    operations = [
        migrations.RunPython(
            make_checkins_unique, migrations.RunPython.noop,
        ),
        migrations.AlterUniqueTogether(
            name='checkin',
            unique_together={('list', 'position')},
        ),
    ]
