Skip to content

Instantly share code, notes, and snippets.

@friek
Created June 8, 2018 12:52
Show Gist options
  • Save friek/b4bc7c17a934a9ab1ad860f0f154d6e0 to your computer and use it in GitHub Desktop.
Save friek/b4bc7c17a934a9ab1ad860f0f154d6e0 to your computer and use it in GitHub Desktop.
ViewSet for the Netbox CustomField
# in extra.api.views
class CustomFieldChoicesViewSet(FieldChoicesViewSet):
def __init__(self, *args, **kwargs):
super(CustomFieldChoicesViewSet, self).__init__(*args, **kwargs)
self._fields = OrderedDict()
for cfc in CustomFieldChoice.objects.all():
self._fields.setdefault(cfc.field.name, [])
self._fields[cfc.field.name].append({'value': cfc.pk, 'label': cfc.value})
def get_view_name(self):
return "Custom Field choices"
# in extra.api.urls
router.register(r'_custom_field_choices', views.CustomFieldChoicesViewSet, base_name='field-choice')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment