Files
Logic/Modules/Backend/account/management/commands/seed_admin_user.py
T
2026-05-11 03:27:21 +03:30

25 lines
840 B
Python

from django.core.management.base import BaseCommand, CommandError
from account.seeds import ADMIN_USER_DATA
from farm_hub.seeds import seed_admin_farm
class Command(BaseCommand):
help = "Create or update the default admin user through the admin farm seeder."
def handle(self, *args, **options):
try:
farm, created = seed_admin_farm()
except ValueError as exc:
raise CommandError(str(exc)) from exc
action = "created" if created else "updated"
user = farm.owner
self.stdout.write(
self.style.SUCCESS(
f"Admin user {action}: username={user.username}, email={user.email}, "
f"phone_number={user.phone_number}, password={ADMIN_USER_DATA['password']}, "
f"farm_uuid={farm.farm_uuid}"
)
)