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:
@ -11,7 +11,7 @@ from .nested_serializers import *
|
||||
# Tenants
|
||||
#
|
||||
|
||||
class TenantGroupSerializer(ValidatedModelSerializer):
|
||||
class TenantGroupSerializer(CustomFieldModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='tenancy-api:tenantgroup-detail')
|
||||
parent = NestedTenantGroupSerializer(required=False, allow_null=True)
|
||||
tenant_count = serializers.IntegerField(read_only=True)
|
||||
@ -19,7 +19,10 @@ class TenantGroupSerializer(ValidatedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = TenantGroup
|
||||
fields = ['id', 'url', 'name', 'slug', 'parent', 'description', 'tenant_count', '_depth']
|
||||
fields = [
|
||||
'id', 'url', 'name', 'slug', 'parent', 'description', 'custom_fields', 'created', 'last_updated',
|
||||
'tenant_count', '_depth',
|
||||
]
|
||||
|
||||
|
||||
class TenantSerializer(TaggedObjectSerializer, CustomFieldModelSerializer):
|
||||
|
@ -4,7 +4,6 @@ from circuits.models import Circuit
|
||||
from dcim.models import Device, Rack, Site
|
||||
from extras.api.views import CustomFieldModelViewSet
|
||||
from ipam.models import IPAddress, Prefix, VLAN, VRF
|
||||
from netbox.api.views import ModelViewSet
|
||||
from tenancy import filters
|
||||
from tenancy.models import Tenant, TenantGroup
|
||||
from utilities.utils import count_related
|
||||
@ -24,7 +23,7 @@ class TenancyRootView(APIRootView):
|
||||
# Tenant Groups
|
||||
#
|
||||
|
||||
class TenantGroupViewSet(ModelViewSet):
|
||||
class TenantGroupViewSet(CustomFieldModelViewSet):
|
||||
queryset = TenantGroup.objects.add_related_count(
|
||||
TenantGroup.objects.all(),
|
||||
Tenant,
|
||||
|
Reference in New Issue
Block a user