skillbox/server/users/management/commands/move_new_raw_to_field.py

27 lines
744 B
Python

from django.core.management.base import BaseCommand
from users.models import License
class Command(BaseCommand):
help = """
Move raw data from new API to own field on License model
"""
def add_arguments(self, parser):
parser.add_argument('--dry-run', action='store_true', dest='dry_run', default=False, help='Make dry-run')
def handle(self, *args, **options):
for license in License.objects.filter(new_api_raw=''):
if license.is_old_api():
continue
license.new_api_raw = license.raw
license.raw = ''
print(f'Moving raw to new API field for licenseID {license.id}')
if not options['dry_run']:
license.save()