feat(chat): add management commands and initial migration

This commit is contained in:
2026-04-28 12:36:42 +02:00
parent 9b16654660
commit 5064eca38a
4 changed files with 18 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
# init
+1
View File
@@ -0,0 +1 @@
# init
+16
View File
@@ -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.'))
View File