# Generated by Django 5.2 on 2025-04-25 15:31

from django.db import migrations


def delete_single_anime_events(apps, schema_editor):
    Event = apps.get_model('events', 'Event')
    Item = apps.get_model('app', 'Item')

    # Get all anime items
    anime_items = Item.objects.filter(media_type='anime')

    for item in anime_items:
        # Get all events for this anime item
        events = Event.objects.filter(item=item)

        # Check if there's exactly one event with content_number=1
        if events.count() == 1 and events.first().content_number == 1:
            events.delete()


class Migration(migrations.Migration):

    dependencies = [
        ('events', '0012_remove_event_unique_item_episode_and_more'),
    ]

    operations = [
        migrations.RunPython(delete_single_anime_events, reverse_code=migrations.RunPython.noop),
    ]
