from django.core.management.base import BaseCommand from apps.files.tasks import generate_video_thumbnail from apps.files.models import PostFileModel from tqdm import tqdm class Command(BaseCommand): help = "Backfill video and gif thumbs" def handle(self, *args, **options): # Get all PostFileModel instances that need thumbs files = PostFileModel.objects.filter(file_type__in=["video", "gif"]) # Create a progress bar pbar = tqdm(total=files.count(), desc="Generating thumbs") # Loop through each file and generate thumbs for file in files: generate_video_thumbnail.delay(file.id) pbar.update(1) pbar.close()