From 5064eca38a63013a09520f48670091f5e01a985b Mon Sep 17 00:00:00 2001 From: Igor Barcik Date: Tue, 28 Apr 2026 12:36:42 +0200 Subject: [PATCH] feat(chat): add management commands and initial migration --- chat/management/__init__.py | 1 + chat/management/commands/__init__.py | 1 + chat/management/commands/init_admin.py | 16 ++++++++++++++++ chat/migrations/__init__.py | 0 4 files changed, 18 insertions(+) create mode 100644 chat/management/__init__.py create mode 100644 chat/management/commands/__init__.py create mode 100644 chat/management/commands/init_admin.py create mode 100644 chat/migrations/__init__.py diff --git a/chat/management/__init__.py b/chat/management/__init__.py new file mode 100644 index 0000000..a6131c1 --- /dev/null +++ b/chat/management/__init__.py @@ -0,0 +1 @@ +# init diff --git a/chat/management/commands/__init__.py b/chat/management/commands/__init__.py new file mode 100644 index 0000000..a6131c1 --- /dev/null +++ b/chat/management/commands/__init__.py @@ -0,0 +1 @@ +# init diff --git a/chat/management/commands/init_admin.py b/chat/management/commands/init_admin.py new file mode 100644 index 0000000..0b062da --- /dev/null +++ b/chat/management/commands/init_admin.py @@ -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.')) diff --git a/chat/migrations/__init__.py b/chat/migrations/__init__.py new file mode 100644 index 0000000..e69de29