Files
zulip/zephyr/management/commands/copy_user_to_userprofile.py
Tim Abbott b82edb6fd6 [manual] Add User fields to the UserProfile model.
And keep the fields updated, by copying on UserProfile creation and
updating the UserProfile object whenever we're updating the User
object, and add management commands to (1) initially ensure that they
match and (2) check that they still match (aka that the updating code
is working).

The copy_user_to_userprofile migration needs to be run after this is
deployed to prod.

(imported from commit 0a598d2e10b1a7a2f5c67dd5140ea4bb8e1ec0b8)
2013-04-01 14:34:25 -04:00

19 lines
759 B
Python

from optparse import make_option
from django.core.management.base import BaseCommand
from zephyr.models import UserProfile, User
class Command(BaseCommand):
option_list = BaseCommand.option_list
help = "Copy all the shared fields from User to UserProfile."
def handle(self, *args, **options):
for user_profile in UserProfile.objects.all():
user = user_profile.user
user_profile.email = user.email
user_profile.is_active = user.is_active
user_profile.is_staff = user.is_staff
user_profile.date_joined = user.date_joined
user_profile.password = user.password
user_profile.save(update_fields=["email", "is_active", "is_staff", "date_joined", "password"])