2019-04-12 17:07:56 -04:00
|
|
|
from django.db.models import Count
|
|
|
|
|
2017-05-24 11:33:11 -04:00
|
|
|
from extras.api.views import CustomFieldModelViewSet
|
2017-06-19 16:10:18 -04:00
|
|
|
from tenancy import filters
|
2016-07-26 14:58:37 -04:00
|
|
|
from tenancy.models import Tenant, TenantGroup
|
2017-11-07 15:36:10 -05:00
|
|
|
from utilities.api import FieldChoicesViewSet, ModelViewSet
|
2016-07-26 14:58:37 -04:00
|
|
|
from . import serializers
|
|
|
|
|
|
|
|
|
2017-10-10 16:41:35 -04:00
|
|
|
#
|
|
|
|
# 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):
|
2019-04-12 17:07:56 -04:00
|
|
|
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
|
|
|
|
2017-11-07 15:36:10 -05:00
|
|
|
class TenantViewSet(CustomFieldModelViewSet):
|
2018-09-28 16:44:05 -04:00
|
|
|
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
|