# Generated by Django 3.2.12 on 2022-04-06 06:19

from django.conf import settings
from django.db import migrations, models


def fix_media_file(apps, schema_editor):
    Media = apps.get_model('sync', 'Media')
    for media in Media.objects.filter(downloaded=True):
        download_dir = str(settings.DOWNLOAD_ROOT)

        if media.media_file.name.startswith(download_dir):
            media.media_file.name = media.media_file.name[len(download_dir) + 1:]
            media.save()


class Migration(migrations.Migration):

    dependencies = [
        ('sync', '0012_alter_media_downloaded_format'),
    ]

    operations = [
        migrations.RunPython(fix_media_file)
    ]
