from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User


class Command(BaseCommand):
    user_name = "admin"
    password = "password123"

    def handle(self, *args, **options):
        if User.objects.filter(username=self.user_name).exists():
            self.stdout.write("Default admin already exists. Skipping.")
            return

        u = User(username=self.user_name)
        u.set_password(self.password)
        u.is_superuser = True
        u.is_staff = True
        u.save()

        self.stdout.write("Created default user {} with password {}.".format(self.user_name, self.password))
