from django.core.management.base import BaseCommand, CommandError from address.search_text import rebuild_search_text class Command(BaseCommand): help = "Пересобрать строку поиска улиц и планировок" def add_arguments(self, parser): parser.add_argument( "--region-code", help="Код субъекта РФ. Без него обновляются все регионы", ) def handle(self, *args, **options): raw = options["region_code"] if raw is None: region_code = None else: code = str(raw).strip() if not code.isdigit() or len(code) > 2: raise CommandError(f"Некорректный код региона: {raw}") region_code = int(code) updated = rebuild_search_text(region_code=region_code) self.stdout.write(self.style.SUCCESS(f"Обновлено search_text: {updated}"))