Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
708 B
1
Indexable
Never
from django.db import migrations


def update_type_file(apps, schema_editor):
    UploadedFile = apps.get_model("files", "UploadedFile")
    for file in UploadedFile.objects.all():
        if file.mime_type in ["image/jpeg", "image/png", "image/gif"]:
            file.type_file = "PH"  # Photo
        elif file.mime_type in ["video/mp4", "video/quicktime"]:
            file.type_file = "VD"  # Video
        else:
            file.type_file = "FL"  # File
        file.save()


class Migration(migrations.Migration):
    dependencies = [
        ("files", "0005_uploadedfile_type_file_alter_uploadedfile_category_and_more"),
    ]

    operations = [
        migrations.RunPython(update_type_file),
    ]
Leave a Comment