Created
June 8, 2018 12:52
-
-
Save friek/b4bc7c17a934a9ab1ad860f0f154d6e0 to your computer and use it in GitHub Desktop.
ViewSet for the Netbox CustomField
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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