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