You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
956 B
Python
35 lines
956 B
Python
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}'
|
|
)
|
|
)
|