39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
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'
|
||
)
|
||
)
|