haikal/inventory/management/commands/serie_translate.py
Marwan Alwali f3cd624851 update
2025-02-25 14:43:25 +03:00

27 lines
977 B
Python

from django.core.management.base import BaseCommand
from inventory.models import CarSerie
TRANSLATIONS = {
"Liftback 5-doors": "ليفت باك - خمسة أبواب",
}
class Command(BaseCommand):
help = "Translate CarSerie model names into Arabic"
def handle(self, *args, **kwargs):
updated_count = 0
for car_serie in CarSerie.objects.all():
arabic_translation = TRANSLATIONS.get(car_serie.name)
if arabic_translation and car_serie.arabic_name != arabic_translation:
car_serie.arabic_name = arabic_translation
car_serie.save()
updated_count += 1
self.stdout.write(self.style.SUCCESS(f"Updated: {car_serie.name} -> {arabic_translation}"))
if updated_count:
self.stdout.write(self.style.SUCCESS(f"Successfully updated {updated_count} entries."))
else:
self.stdout.write(self.style.WARNING("No updates were made."))