Skip to content

Commit e383fd4

Browse files
committed
Fix custom fields initializer
1 parent 234baa4 commit e383fd4

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

initializers/custom_fields.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
# - Third Item
5353
# - Fifth Item
5454
# - Fourth Item
55-
# select_field_auto_weight:
55+
# select_field_legacy_format:
5656
# type: select
5757
# label: Choose between items
5858
# required: false
@@ -61,11 +61,12 @@
6161
# on_objects:
6262
# - dcim.models.Device
6363
# choices:
64-
# - A
65-
# - B
66-
# - C
67-
# - E
68-
# - D like deprecated
64+
# - value: A # this is the deprecated format.
65+
# - value: B # we only use it for the tests.
66+
# - value: C # please see above for the new format.
67+
# - value: "D like deprecated"
68+
# weight: 999
69+
# - value: E
6970
# boolean_field:
7071
# type: boolean
7172
# label: Yes Or No?

startup_scripts/000_users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22

3-
from django.contrib.auth.models import Group, User
3+
from django.contrib.auth.models import User
44
from startup_script_utils import load_yaml, set_permissions
55
from users.models import Token
66

startup_scripts/020_custom_fields.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ def get_class_for_class_path(class_path):
4545
if cf_details.get('choices', False):
4646
custom_field.choices = []
4747

48-
for choice_detail in enumerate(cf_details.get('choices', [])):
49-
if isinstance(choice_detail, str):
50-
custom_field.choices.append(choice_detail)
51-
else: # legacy mode
52-
print(f"⚠️ Please migrate the 'choices' of '{cf_name}' to the new format, as 'weight' is no longer supported!")
48+
for choice_detail in cf_details.get('choices', []):
49+
if isinstance(choice_detail, dict) and 'value' in choice_detail:
50+
# legacy mode
51+
print(f"⚠️ Please migrate the choice '{choice_detail['value']}' of '{cf_name}' to the new format, as 'weight' is no longer supported!")
5352
custom_field.choices.append(choice_detail['value'])
53+
else:
54+
custom_field.choices.append(choice_detail)
5455

5556
custom_field.save()
5657

0 commit comments

Comments
 (0)