Merge pull request #55 from Grokzen/auto_weight_choices
Add support for auto_weight counter
This commit is contained in:
commit
8333fafcf1
|
@ -39,6 +39,21 @@
|
|||
# weight: 50
|
||||
# - value: Fourth Item
|
||||
# weight: 40
|
||||
# selection_field_auto_weight:
|
||||
# type: selection
|
||||
# label: Choose between items
|
||||
# required: false
|
||||
# filterable: true
|
||||
# weight: 30
|
||||
# on_objects:
|
||||
# - dcim.models.Device
|
||||
# choices:
|
||||
# - value: A
|
||||
# - value: B
|
||||
# - value: C
|
||||
# - value: "D like deprecated"
|
||||
# weight: 999
|
||||
# - value: E
|
||||
# boolean_field:
|
||||
# type: boolean
|
||||
# label: Yes Or No?
|
||||
|
|
|
@ -59,13 +59,11 @@ with open('/opt/netbox/initializers/custom_fields.yml', 'r') as stream:
|
|||
|
||||
custom_field.save()
|
||||
|
||||
for choice_details in cf_details.get('choices', []):
|
||||
choice = CustomFieldChoice.objects.create(
|
||||
for idx, choice_details in enumerate(cf_details.get('choices', [])):
|
||||
choice, _ = CustomFieldChoice.objects.get_or_create(
|
||||
field=custom_field,
|
||||
value=choice_details['value'])
|
||||
|
||||
if choice_details.get('weight', 0):
|
||||
choice.weight = choice_details['weight']
|
||||
choice.save()
|
||||
value=choice_details['value'],
|
||||
defaults={'weight': idx * 10}
|
||||
)
|
||||
|
||||
print("🔧 Created custom field", cf_name)
|
||||
|
|
Loading…
Reference in New Issue