Merge pull request #55 from Grokzen/auto_weight_choices

Add support for auto_weight counter
This commit is contained in:
Demian 2018-06-26 09:03:15 +02:00 committed by GitHub
commit 8333fafcf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -39,6 +39,21 @@
# weight: 50 # weight: 50
# - value: Fourth Item # - value: Fourth Item
# weight: 40 # 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: # boolean_field:
# type: boolean # type: boolean
# label: Yes Or No? # label: Yes Or No?

View File

@ -59,13 +59,11 @@ with open('/opt/netbox/initializers/custom_fields.yml', 'r') as stream:
custom_field.save() custom_field.save()
for choice_details in cf_details.get('choices', []): for idx, choice_details in enumerate(cf_details.get('choices', [])):
choice = CustomFieldChoice.objects.create( choice, _ = CustomFieldChoice.objects.get_or_create(
field=custom_field, field=custom_field,
value=choice_details['value']) value=choice_details['value'],
defaults={'weight': idx * 10}
if choice_details.get('weight', 0): )
choice.weight = choice_details['weight']
choice.save()
print("🔧 Created custom field", cf_name) print("🔧 Created custom field", cf_name)