Geen omschrijving

create_profile.py 590B

123456789101112131415
  1. from django.core.management.base import BaseCommand
  2. from django.contrib.auth.models import User
  3. from sysadmin.models import UserProfile
  4. class Command(BaseCommand):
  5. help = "Create missing profiles for existing users"
  6. def handle(self, *args, **kwargs):
  7. users_without_profiles = User.objects.filter(profile__isnull=True)
  8. for user in users_without_profiles:
  9. UserProfile.objects.create(user=user)
  10. self.stdout.write(f"Created profile for {user.username}")
  11. self.stdout.write(self.style.SUCCESS("All missing profiles have been created!"))