diff --git a/README.md b/README.md index a9ea2c6..06c2699 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,15 @@ docker-compose up --build -d docker exec -it bash python manage.py createclient -``` \ No newline at end of file +``` + +## SuperUser yaratish uchun +``` bash +python manage.py createuser +``` +- Schema name: -> client qoshishda kiritgan schema name. +- Username: -> login qilish uchun username. +- First name: -> Ism (shart emas). +- Last name: -> Familiya (shart emas). +- Phone number: -> Telefon raqam (shart emas). +- Password: -> login qilish uchun parol. \ No newline at end of file diff --git a/core/apps/accounts/management/__init__.py b/core/apps/accounts/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/accounts/management/commands/createuser.py b/core/apps/accounts/management/commands/createuser.py new file mode 100644 index 0000000..e9f8fc9 --- /dev/null +++ b/core/apps/accounts/management/commands/createuser.py @@ -0,0 +1,53 @@ +# pypi +from getpass import getpass + +# django +from django.contrib.auth.management.commands.createsuperuser import Command as SuperUserCommand + +# django tenants +from django_tenants.utils import schema_context + +# accounts +from core.apps.accounts.models import User +# customers +from core.apps.customers.models import Client + + +class Command(SuperUserCommand): + def handle(self, *args, **options): + while True: + schema = input("Enter schema name: ") + + client = Client.objects.filter(schema_name=schema).first() + + if not client: + self.stdout.write(self.style.WARNING("Schema not found")) + else: + break + + while True: + username = input("Enter username: ") + if User.objects.filter(username=username).exists(): + self.stdout.write(self.style.WARNING("User already exists")) + else: + break + first_name = input("Enter first name: ") + last_name = input("Enter last name: ") + phone_number = input("Enter phone number: ") + + password = getpass("Enter password: ") + + User.objects.create_superuser( + password=password, + username=username, + client=client, + first_name=first_name, + last_name=last_name, + phone_number=phone_number, + ) + + self.stdout.write( + self.style.SUCCESS( + f"Superuser created successfully in schema '{schema}'" + ) + ) \ No newline at end of file