39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
|
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!")
|