feat(chat): add management commands and initial migration
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
# init
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
# init
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from chat.models import UserProfile
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Create default admin user if it does not exist'
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
if not User.objects.filter(username='admin').exists():
|
||||||
|
u = User.objects.create_superuser('admin', 'admin@example.com', 'admin')
|
||||||
|
p, _ = UserProfile.objects.get_or_create(user=u)
|
||||||
|
p.role = 'admin'
|
||||||
|
p.save()
|
||||||
|
self.stdout.write(self.style.SUCCESS('Successfully created admin user.'))
|
||||||
|
else:
|
||||||
|
self.stdout.write(self.style.SUCCESS('Admin user already exists.'))
|
||||||
Reference in New Issue
Block a user