This commit is contained in:
2025-03-07 09:37:28 +08:00
parent 7cb13333eb
commit 3b52eb1813
4 changed files with 8 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ from .schemas import (
UserRegistrationSchema, UserRegistrationSchema,
UserLoginSchema, UserLoginSchema,
) )
from .models import Profile, RoleChoices, User from .models import Profile, RoleChoices, User, create_user_profile
from .decorators import super_required from .decorators import super_required
router = Router() router = Router()
@@ -91,9 +91,9 @@ def batch_create(request, payload: BatchUsersIn):
for user in user_list: for user in user_list:
profile_list.append(Profile(user=user)) profile_list.append(Profile(user=user))
post_save.disconnect(sender=User, dispatch_uid="1") post_save.disconnect(create_user_profile, sender=User)
User.objects.bulk_create(user_list) User.objects.bulk_create(user_list)
post_save.connect(sender=User, dispatch_uid="1") post_save.connect(create_user_profile, sender=User)
Profile.objects.bulk_create(profile_list) Profile.objects.bulk_create(profile_list)
return {"message": "批量创建成功"} return {"message": "批量创建成功"}

View File

@@ -1,4 +1,4 @@
# Generated by Django 5.1.6 on 2025-03-06 16:03 # Generated by Django 5.1.6 on 2025-03-07 01:32
import django.contrib.auth.models import django.contrib.auth.models
import django.contrib.auth.validators import django.contrib.auth.validators
@@ -25,8 +25,6 @@ class Migration(migrations.Migration):
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),

View File

@@ -12,6 +12,9 @@ class RoleChoices(models.TextChoices):
class User(AbstractUser): class User(AbstractUser):
first_name = None
last_name = None
role = models.CharField( role = models.CharField(
max_length=20, max_length=20,
choices=RoleChoices.choices, choices=RoleChoices.choices,

View File

@@ -1,4 +1,4 @@
# Generated by Django 5.1.6 on 2025-03-06 16:03 # Generated by Django 5.1.6 on 2025-03-07 01:32
import django.db.models.deletion import django.db.models.deletion
import django_extensions.db.fields import django_extensions.db.fields