diff --git a/photologue/migrations/0009_regen_thumbnails.py b/photologue/migrations/0009_regen_thumbnails.py new file mode 100644 index 0000000..b4d0028 --- /dev/null +++ b/photologue/migrations/0009_regen_thumbnails.py @@ -0,0 +1,31 @@ +from django.db import migrations + + +def regen_thumbnails(apps, schema_editor): + Photo = apps.get_model("photologue", "Photo") + PhotoSize = apps.get_model("photologue", "PhotoSize") + + try: + thumbnail = PhotoSize.objects.get(name="thumbnail") + except PhotoSize.DoesNotExist: + return + + for photo in Photo.objects.all(): + # Use the real model instance to access file methods + from photologue.models import Photo as RealPhoto + try: + real_photo = RealPhoto.objects.get(pk=photo.pk) + real_photo.remove_size(thumbnail) + except Exception: + pass + + +class Migration(migrations.Migration): + + dependencies = [ + ("photologue", "0008_photo_dimensions"), + ] + + operations = [ + migrations.RunPython(regen_thumbnails, migrations.RunPython.noop), + ]