mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Add custom field support for organizational models to API serializers
This commit is contained in:
@ -15,13 +15,15 @@ from .nested_serializers import *
|
||||
# Secrets
|
||||
#
|
||||
|
||||
class SecretRoleSerializer(ValidatedModelSerializer):
|
||||
class SecretRoleSerializer(CustomFieldModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='secrets-api:secretrole-detail')
|
||||
secret_count = serializers.IntegerField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = SecretRole
|
||||
fields = ['id', 'url', 'name', 'slug', 'description', 'secret_count']
|
||||
fields = [
|
||||
'id', 'url', 'name', 'slug', 'description', 'custom_fields', 'created', 'last_updated', 'secret_count',
|
||||
]
|
||||
|
||||
|
||||
class SecretSerializer(TaggedObjectSerializer, CustomFieldModelSerializer):
|
||||
|
@ -8,6 +8,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.routers import APIRootView
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from extras.api.views import CustomFieldModelViewSet
|
||||
from netbox.api.views import ModelViewSet
|
||||
from secrets import filters
|
||||
from secrets.exceptions import InvalidKey
|
||||
@ -33,7 +34,7 @@ class SecretsRootView(APIRootView):
|
||||
# Secret Roles
|
||||
#
|
||||
|
||||
class SecretRoleViewSet(ModelViewSet):
|
||||
class SecretRoleViewSet(CustomFieldModelViewSet):
|
||||
queryset = SecretRole.objects.annotate(
|
||||
secret_count=count_related(Secret, 'role')
|
||||
)
|
||||
|
Reference in New Issue
Block a user