18 lines
713 B
Python
18 lines
713 B
Python
|
# 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")
|