2017-10-22 20:50:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-02-06 14:59:57 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
2017-10-22 20:50:47 +00:00
|
|
|
from django.core.management.commands import migrate
|
|
|
|
|
|
|
|
|
|
|
|
class Command(migrate.Command):
|
2022-02-10 00:00:30 +00:00
|
|
|
help = "Creates an initial User (admin/admin) for Baby Buddy."
|
2017-10-22 20:50:47 +00:00
|
|
|
|
|
|
|
def handle(self, *args, **kwargs):
|
|
|
|
super(Command, self).handle(*args, **kwargs)
|
|
|
|
|
2023-02-06 14:59:57 +00:00
|
|
|
superusers = get_user_model().objects.filter(is_superuser=True)
|
2017-10-22 20:50:47 +00:00
|
|
|
if len(superusers) == 0:
|
2023-02-08 04:29:15 +00:00
|
|
|
default_user = get_user_model().objects.create_user(
|
|
|
|
"admin", password="admin"
|
|
|
|
)
|
2017-10-22 20:50:47 +00:00
|
|
|
default_user.is_superuser = True
|
|
|
|
default_user.is_staff = True
|
|
|
|
default_user.save()
|