一个家庭日报系统
This commit is contained in:
18
core/management/commands/create_superuser.py
Normal file
18
core/management/commands/create_superuser.py
Normal file
@@ -0,0 +1,18 @@
|
||||
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.'))
|
||||
Reference in New Issue
Block a user