Аутентификация и кто и когда создал
This commit is contained in:
20
dbapp/mainapp/management/commands/create_user_profiles.py
Normal file
20
dbapp/mainapp/management/commands/create_user_profiles.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
from mainapp.models import CustomUser
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Create CustomUser profiles for existing users who do not have them'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# Find all users who don't have a CustomUser profile
|
||||
for user in User.objects.all():
|
||||
if not hasattr(user, 'customuser'):
|
||||
custom_user = CustomUser.objects.create(user=user)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'Created CustomUser for {user.username}')
|
||||
)
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS('Successfully ensured all users have CustomUser profiles')
|
||||
)
|
||||
Reference in New Issue
Block a user