from django.core.management.base import BaseCommand from django.contrib.auth.models import User class Command(BaseCommand): help = 'Creates a superuser.' def handle(self, *args, **options): if not User.objects.filter(username='admin').exists(): User.objects.create_superuser('admin', 'admin@example.com', 'admin') self.stdout.write(self.style.SUCCESS('Successfully created superuser.'))