from django.core.management.base import BaseCommand
from django.utils.text import slugify

from apps.station.models import StationMaster


class Command(BaseCommand):
    help = "Updates slugs for existing stations"

    def handle(self, *args, **options):
        stations = StationMaster.objects.all()
        for station in stations:
            station.slug = slugify(f"{station.name}-{station.pk}")
            station.save()
            self.stdout.write(self.style.SUCCESS(f"Slug updated for {station.name}"))
