core/apps/accounts: super user qoshish uchun management command qoshildig
This commit is contained in:
13
README.md
13
README.md
@@ -13,4 +13,15 @@ docker-compose up --build -d
|
||||
docker exec -it <container_name> bash
|
||||
|
||||
python manage.py createclient
|
||||
```
|
||||
```
|
||||
|
||||
## 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.
|
||||
0
core/apps/accounts/management/__init__.py
Normal file
0
core/apps/accounts/management/__init__.py
Normal file
53
core/apps/accounts/management/commands/createuser.py
Normal file
53
core/apps/accounts/management/commands/createuser.py
Normal file
@@ -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}'"
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user