Fix imagekit properties & add regenerate thumbnails command

This commit is contained in:
Nyymix 2025-01-19 21:26:03 +02:00
parent b7c183d2f3
commit ff3567d3d0
3 changed files with 48 additions and 6 deletions

View file

@ -0,0 +1,38 @@
from django.core.management.base import BaseCommand
from imagekit.cachefiles import ImageCacheFile
from gallery.models import Photo
class Command(BaseCommand):
help = 'Regenerate all thumbnails (photo_sm, photo_md, photo_bg)'
def handle(self, *args, **kwargs):
photos = Photo.objects.all()
total = photos.count()
for idx, photo in enumerate(photos, 1):
print(f"Processing {idx}/{total}: {photo.photo.name}")
# Regenerate photo_sm
try:
photo.photo_sm.generate()
print(f" - photo_sm regenerated")
except Exception as e:
print(f" - Error generating photo_sm: {e}")
# Regenerate photo_md
try:
photo.photo_md.generate()
print(f" - photo_md regenerated")
except Exception as e:
print(f" - Error generating photo_md: {e}")
# Regenerate photo_bg
try:
photo.photo_bg.generate()
print(f" - photo_bg regenerated")
except Exception as e:
print(f" - Error generating photo_bg: {e}")
print("Thumbnail regeneration completed!")