Add: user profile backfill management command
This commit is contained in:
parent
2efe7f9b24
commit
4f967020da
3 changed files with 17 additions and 0 deletions
0
backend/api/user/management/__init__.py
Normal file
0
backend/api/user/management/__init__.py
Normal file
0
backend/api/user/management/commands/__init__.py
Normal file
0
backend/api/user/management/commands/__init__.py
Normal 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")
|
Loading…
Add table
Reference in a new issue