shared_accounts, accounts: ikkita user model qoshildi
This commit is contained in:
@@ -11,7 +11,7 @@ from core.apps.accounts.models.user import User
|
||||
class UserAdmin(DjangoUserAdmin):
|
||||
fieldsets = (
|
||||
(None, {"fields": ("username", "password")}),
|
||||
(("Personal info"), {"fields": ("first_name", "last_name", "email", "client", "phone_number", "profile_image")}),
|
||||
(("Personal info"), {"fields": ("first_name", "last_name", "email", "phone_number", "profile_image")}),
|
||||
(
|
||||
("Permissions"),
|
||||
{
|
||||
@@ -29,11 +29,12 @@ class UserAdmin(DjangoUserAdmin):
|
||||
None,
|
||||
{
|
||||
"classes": ("wide",),
|
||||
"fields": ("username", "password1", "password2", "client"),
|
||||
"fields": ("username", "first_name", "last_name", "phone_number", "password1", "password2"),
|
||||
},
|
||||
),
|
||||
)
|
||||
list_display = ("username", "phone_number", "first_name", "last_name", "is_staff")
|
||||
list_filter = ("is_staff", "is_superuser", "is_active", "groups")
|
||||
list_filter = ("is_staff", "is_superuser", "is_active")
|
||||
search_fields = ("username", "first_name", "last_name", "email")
|
||||
ordering = ("username",)
|
||||
ordering = ("username",)
|
||||
filter_horizontal = ()
|
||||
@@ -1,53 +0,0 @@
|
||||
# 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}'"
|
||||
)
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
# Generated by Django 5.2 on 2025-12-05 11:43
|
||||
# Generated by Django 5.2 on 2025-12-07 09:47
|
||||
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
@@ -12,7 +12,6 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@@ -33,9 +32,7 @@ class Migration(migrations.Migration):
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('profile_image', models.ImageField(blank=True, null=True, upload_to='user/profile_images/')),
|
||||
('phone_number', models.CharField(blank=True, max_length=15, null=True, validators=[django.core.validators.RegexValidator(message='The phone_number is invalid. The format should be like this: 998XXXXXXXXX', regex='^998\\d{9}$')])),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
('phone_number', models.CharField(blank=True, max_length=15, null=True, validators=[django.core.validators.RegexValidator(message='The phone_number is invalid. The format should be like this: +998XXXXXXXXX', regex='^\\+998\\d{9}$')])),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'user',
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# Generated by Django 5.2 on 2025-12-05 12:07
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0001_initial'),
|
||||
('customers', '0002_remove_client_on_trial_remove_client_paid_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='client',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='users', to='customers.client'),
|
||||
),
|
||||
]
|
||||
@@ -21,9 +21,8 @@ class User(AbstractUser, BaseModel):
|
||||
phone_number = models.CharField(
|
||||
max_length=15, null=True, blank=True, validators=[uz_phone_validator]
|
||||
)
|
||||
client = models.ForeignKey(
|
||||
Client, on_delete=models.CASCADE, related_name='users', null=True,
|
||||
)
|
||||
groups = None
|
||||
user_permissions = None
|
||||
|
||||
def __str__(self):
|
||||
return f"#{self.id}: {self.first_name} {self.last_name}"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# django
|
||||
from django.urls import path, include
|
||||
|
||||
# rest framework simplejwt
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('user/', include(
|
||||
[
|
||||
|
||||
]
|
||||
)),
|
||||
# ------ authentication ------
|
||||
path('auth/', include(
|
||||
[
|
||||
path('login/', TokenObtainPairView.as_view(), name='login-api'),
|
||||
path('token/refresh/', TokenRefreshView.as_view(), name='token-refresh-api'),
|
||||
]
|
||||
)),
|
||||
]
|
||||
Reference in New Issue
Block a user