Browse Source

Create admin if it doesn't exist

pull/293/head
Clemens Wolff 5 years ago
parent
commit
7e30a1e756
1 changed files with 5 additions and 1 deletions
  1. 6
      app/server/management/commands/create_admin.py

6
app/server/management/commands/create_admin.py

@ -1,5 +1,6 @@
from django.contrib.auth.management.commands import createsuperuser
from django.core.management import CommandError
from django.db import IntegrityError
class Command(createsuperuser.Command):
@ -17,7 +18,10 @@ class Command(createsuperuser.Command):
if password and not username:
raise CommandError('--username is required if specifying --password')
super().handle(*args, **options)
try:
super().handle(*args, **options)
except IntegrityError:
self.stderr.write(f'User {username} already exists.')
if password:
database = options.get('database')

Loading…
Cancel
Save