import csv
from django.core.management.base import BaseCommand
from career.models import State, Country

class Command(BaseCommand):
    help = 'Import states from CSV and assign country_id=1'

    def handle(self, *args, **options):
        country = Country.objects.get(pk=1)
        with open('/var/www/apihucms/State-2025-07-30.csv', newline='', encoding='utf-8') as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                state_name = row['state_name']
                State.objects.get_or_create(name=state_name, country=country)
        self.stdout.write(self.style.SUCCESS('States imported successfully.'))
