Files
Backend/account/management/commands/seed_admin_user.py
T

25 lines
840 B
Python
Raw Normal View History

2026-03-26 15:39:31 +03:30
from django.core.management.base import BaseCommand, CommandError
2026-04-04 01:16:16 +03:30
from account.seeds import ADMIN_USER_DATA
from farm_hub.seeds import seed_admin_farm
2026-03-26 15:39:31 +03:30
class Command(BaseCommand):
2026-04-04 01:16:16 +03:30
help = "Create or update the default admin user through the admin farm seeder."
2026-03-26 15:39:31 +03:30
def handle(self, *args, **options):
try:
2026-04-04 01:16:16 +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"
2026-04-04 01:16:16 +03:30
user = farm.owner
2026-03-26 15:39:31 +03:30
self.stdout.write(
self.style.SUCCESS(
f"Admin user {action}: username={user.username}, email={user.email}, "
2026-04-04 01:16:16 +03:30
f"phone_number={user.phone_number}, password={ADMIN_USER_DATA['password']}, "
f"farm_uuid={farm.farm_uuid}"
2026-03-26 15:39:31 +03:30
)
)