20 lines
771 B
Python
20 lines
771 B
Python
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')
|
|
) |