18 lines
702 B
Python
18 lines
702 B
Python
from django.contrib.auth import get_user_model
|
|
from django.core.management.base import BaseCommand
|
|
|
|
class Command(BaseCommand):
|
|
"""非交互式创建超级用户"""
|
|
help = 'Create a superuser non-interactively'
|
|
|
|
def handle(self, *args, **options):
|
|
User = get_user_model()
|
|
if not User.objects.filter(username='admin').exists():
|
|
User.objects.create_superuser(
|
|
username='admin',
|
|
email='admin@example.com',
|
|
password='admin123'
|
|
)
|
|
self.stdout.write(self.style.SUCCESS('Superuser created successfully!'))
|
|
else:
|
|
self.stdout.write(self.style.WARNING('Superuser already exists.')) |