Add: user profile backfill management command

This commit is contained in:
Aroy-Art 2025-01-31 22:47:34 +01:00
parent 2efe7f9b24
commit 4f967020da
Signed by: Aroy
GPG key ID: 583642324A1D2070
3 changed files with 17 additions and 0 deletions

View file

View file

@ -0,0 +1,17 @@
# api/user/management/commands/backfill_user_profiles.py
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from api.user.models import UserProfile # assuming you have a UserProfile model
class Command(BaseCommand):
help = "Backfill user profiles for existing users"
def handle(self, *args, **options):
users = User.objects.all()
for user in users:
if not UserProfile.objects.filter(user=user).exists():
# create a new user profile
UserProfile.objects.create(user=user)
self.stdout.write(f"Created user profile for {user.username}")
self.stdout.write("Backfill complete")