Skip to content

Commit c001626

Browse files
committed
Update Custom Fields Initializer for Netbox 2.7
The custom field database model has changed in Netbox 2.7. Therefore the initializer code, that was used before, broke. As a user, you will need to update your custom_fields.yml file as follows: - type must be lowercase - the `selection` type was changed to `select` - the filter_logic must be lower case This is to achieve compatibility with the naming schema that Netbox uses internally. It allows us to become forward compatible in case Netbox ever introduces a new type for custom fields. See the diff of this commit for further information how this is meant.
1 parent 355f9d4 commit c001626

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

initializers/custom_fields.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## Possible Choices:
2+
## type:
3+
## - text
4+
## - integer
5+
## - boolean
6+
## - date
7+
## - url
8+
## - select
9+
## filter_logic:
10+
## - disabled
11+
## - loose
12+
## - exact
13+
##
14+
## Examples:
15+
116
# text_field:
217
# type: text
318
# label: Custom Text
@@ -22,8 +37,8 @@
2237
# weight: 10
2338
# on_objects:
2439
# - tenancy.models.Tenant
25-
# selection_field:
26-
# type: selection
40+
# select_field:
41+
# type: select
2742
# label: Choose between items
2843
# required: false
2944
# filter_logic: exact
@@ -41,8 +56,8 @@
4156
# weight: 50
4257
# - value: Fourth Item
4358
# weight: 40
44-
# selection_field_auto_weight:
45-
# type: selection
59+
# select_field_auto_weight:
60+
# type: select
4661
# label: Choose between items
4762
# required: false
4863
# filter_logic: loose

startup_scripts/020_custom_fields.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
from extras.constants import CF_TYPE_TEXT, CF_TYPE_INTEGER, CF_TYPE_BOOLEAN, CF_TYPE_DATE, CF_TYPE_URL, CF_TYPE_SELECT, CF_FILTER_CHOICES
21
from extras.models import CustomField, CustomFieldChoice
32

43
from ruamel.yaml import YAML
54
from pathlib import Path
65
import sys
76

8-
text_to_fields = {
9-
'boolean': CF_TYPE_BOOLEAN,
10-
'date': CF_TYPE_DATE,
11-
'integer': CF_TYPE_INTEGER,
12-
'selection': CF_TYPE_SELECT,
13-
'text': CF_TYPE_TEXT,
14-
'url': CF_TYPE_URL,
15-
}
16-
177
def get_class_for_class_path(class_path):
188
import importlib
199
from django.contrib.contenttypes.models import ContentType
@@ -42,12 +32,6 @@ def get_class_for_class_path(class_path):
4232
if cf_details.get('description', 0):
4333
custom_field.description = cf_details['description']
4434

45-
# If no filter_logic is specified then it will default to 'Loose'
46-
if cf_details.get('filter_logic', 0):
47-
for choice_id, choice_text in CF_FILTER_CHOICES:
48-
if choice_text.lower() == cf_details['filter_logic']:
49-
custom_field.filter_logic = choice_id
50-
5135
if cf_details.get('label', 0):
5236
custom_field.label = cf_details['label']
5337

@@ -58,7 +42,7 @@ def get_class_for_class_path(class_path):
5842
custom_field.required = cf_details['required']
5943

6044
if cf_details.get('type', 0):
61-
custom_field.type = text_to_fields[cf_details['type']]
45+
custom_field.type = cf_details['type']
6246

6347
if cf_details.get('weight', 0):
6448
custom_field.weight = cf_details['weight']

0 commit comments

Comments
 (0)