# Generated by Django 5.0.6 on 2024-07-23 21:12

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

def clone_items(apps, schema_editor):
    """Clone the items from the old model to the new one."""
    existing_items = apps.get_model("lists", "Item").objects.all()

    new_items = []
    for item in existing_items:
        new_item = apps.get_model("app", "Item")(
            media_id=item.media_id,
            media_type=item.media_type,
            title=item.title,
            image=item.image,
            season_number=item.season_number,
            episode_number=item.episode_number,
        )
        new_items.append(new_item)

    apps.get_model("app", "Item").objects.bulk_create(new_items)


class Migration(migrations.Migration):

    dependencies = [
        ('app', '0018_item'),
        ('lists', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(clone_items),
        migrations.AlterField(
            model_name='customlistitem',
            name='item',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.item'),
        ),
        migrations.AlterField(
            model_name='customlist',
            name='items',
            field=models.ManyToManyField(blank=True, related_name='custom_lists', through='lists.CustomListItem', to='app.item'),
        ),
        migrations.DeleteModel(
            name='Item',
        ),
    ]
