1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

38 lines
838 B
Python
Raw Normal View History

from django.db.models import Count
2017-05-24 11:33:11 -04:00
from extras.api.views import CustomFieldModelViewSet
from tenancy import filters
2016-07-26 14:58:37 -04:00
from tenancy.models import Tenant, TenantGroup
from utilities.api import FieldChoicesViewSet, ModelViewSet
2016-07-26 14:58:37 -04:00
from . import serializers
#
# Field choices
#
class TenancyFieldChoicesViewSet(FieldChoicesViewSet):
fields = ()
2017-01-24 17:12:16 -05:00
#
# Tenant Groups
#
2016-07-26 14:58:37 -04:00
2017-01-24 17:12:16 -05:00
class TenantGroupViewSet(ModelViewSet):
queryset = TenantGroup.objects.annotate(
tenant_count=Count('tenants')
)
2016-07-26 14:58:37 -04:00
serializer_class = serializers.TenantGroupSerializer
2018-11-02 13:46:28 -04:00
filterset_class = filters.TenantGroupFilter
2016-07-26 14:58:37 -04:00
2017-01-24 17:12:16 -05:00
#
# Tenants
#
2016-07-26 14:58:37 -04:00
class TenantViewSet(CustomFieldModelViewSet):
queryset = Tenant.objects.select_related('group').prefetch_related('tags')
2016-07-26 14:58:37 -04:00
serializer_class = serializers.TenantSerializer
2018-11-02 13:46:28 -04:00
filterset_class = filters.TenantFilter