Files
shopback/blog/management/commands/generate_blog_thumbs.py
Beyhan Oğur d9f1ea341e first commit
2026-04-26 22:27:56 +03:00

39 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.core.management.base import BaseCommand
from blog.models import Post
class Command(BaseCommand):
help = 'Tüm blog postları için eksik thumb dosyalarını oluşturur'
def handle(self, *args, **options):
posts = Post.objects.filter(image__isnull=False)
total = posts.count()
created = 0
skipped = 0
self.stdout.write(f'\n{total} post kontrol ediliyor...\n')
for post in posts:
if not post.thumb:
try:
post.save() # save() metodu thumb'ı otomatik oluşturacak
created += 1
self.stdout.write(
self.style.SUCCESS(f'✓ Thumb oluşturuldu: {post.title}')
)
except Exception as e:
self.stdout.write(
self.style.ERROR(f'✗ Hata ({post.title}): {str(e)}')
)
else:
skipped += 1
self.stdout.write(
self.style.WARNING(f'- Atlandı (zaten var): {post.title}')
)
self.stdout.write(
self.style.SUCCESS(
f'\n✓ Tamamlandı! {created} thumb oluşturuldu, {skipped} atlandı.\n'
)
)