mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #4871: Specify ordering for querysets using annotate() to count related objects
This commit is contained in:
@@ -15,8 +15,12 @@ from . import serializers
|
||||
#
|
||||
|
||||
class TenantGroupViewSet(ModelViewSet):
|
||||
queryset = TenantGroup.objects.annotate(
|
||||
tenant_count=get_subquery(Tenant, 'group')
|
||||
queryset = TenantGroup.objects.add_related_count(
|
||||
TenantGroup.objects.all(),
|
||||
Tenant,
|
||||
'group',
|
||||
'tenant_count',
|
||||
cumulative=True
|
||||
)
|
||||
serializer_class = serializers.TenantGroupSerializer
|
||||
filterset_class = filters.TenantGroupFilterSet
|
||||
|
Reference in New Issue
Block a user