Fix custom fields initializer

This commit is contained in:
Christian Mäder 2020-12-14 22:09:08 +01:00
parent 234baa40a5
commit e383fd42bd
3 changed files with 14 additions and 12 deletions

View file

@ -1,6 +1,6 @@
import sys
from django.contrib.auth.models import Group, User
from django.contrib.auth.models import User
from startup_script_utils import load_yaml, set_permissions
from users.models import Token

View file

@ -45,12 +45,13 @@ for cf_name, cf_details in customfields.items():
if cf_details.get('choices', False):
custom_field.choices = []
for choice_detail in enumerate(cf_details.get('choices', [])):
if isinstance(choice_detail, str):
custom_field.choices.append(choice_detail)
else: # legacy mode
print(f"⚠️ Please migrate the 'choices' of '{cf_name}' to the new format, as 'weight' is no longer supported!")
for choice_detail in cf_details.get('choices', []):
if isinstance(choice_detail, dict) and 'value' in choice_detail:
# legacy mode
print(f"⚠️ Please migrate the choice '{choice_detail['value']}' of '{cf_name}' to the new format, as 'weight' is no longer supported!")
custom_field.choices.append(choice_detail['value'])
else:
custom_field.choices.append(choice_detail)
custom_field.save()