Files
Backend/farm_hub/management/commands/seed_admin_farm.py
T

21 lines
646 B
Python
Raw Normal View History

2026-03-26 15:39:31 +03:30
from django.core.management.base import BaseCommand, CommandError
2026-04-02 23:25:39 +03:30
from farm_hub.seeds import seed_admin_farm
2026-03-26 15:39:31 +03:30
class Command(BaseCommand):
2026-04-02 23:25:39 +03:30
help = "Create or update the default farm hub for the admin user."
2026-03-26 15:39:31 +03:30
def handle(self, *args, **options):
try:
2026-04-02 23:25:39 +03:30
farm, created = seed_admin_farm()
2026-03-26 15:39:31 +03:30
except ValueError as exc:
raise CommandError(str(exc)) from exc
action = "created" if created else "updated"
self.stdout.write(
self.style.SUCCESS(
2026-04-02 23:25:39 +03:30
f"Admin farm {action}: farm_uuid={farm.farm_uuid}, name={farm.name}, owner={farm.owner.username}"
2026-03-26 15:39:31 +03:30
)
)