from django.core.management.base import BaseCommand from api.models import User class Command(BaseCommand): help = 'Creates predefined admin user (username: admin, password: admin)' def handle(self, *args, **options): username = 'admin' password = 'admin' if User.objects.filter(username=username).exists(): self.stdout.write( self.style.WARNING(f'User "{username}" already exists') ) return user = User.objects.create( username=username, email='admin@scalesapp.com', role='employee', is_admin=True, is_staff=True, is_superuser=True, is_active=True ) user.set_password(password) user.save() self.stdout.write( self.style.SUCCESS( f'Successfully created admin user: {username} / {password}' ) )