31 lines
844 B
Python
31 lines
844 B
Python
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),
|
|
]
|