mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Potential fix for #419: Ditch annotation in favor of discrete queries to gather Tenant stats
This commit is contained in:
@@ -2,6 +2,9 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.db.models import Count
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from circuits.models import Circuit
|
||||
from dcim.models import Site, Rack, Device
|
||||
from ipam.models import IPAddress, Prefix, VLAN, VRF
|
||||
from utilities.views import (
|
||||
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
||||
)
|
||||
@@ -50,19 +53,21 @@ class TenantListView(ObjectListView):
|
||||
|
||||
def tenant(request, slug):
|
||||
|
||||
tenant = get_object_or_404(Tenant.objects.annotate(
|
||||
site_count=Count('sites', distinct=True),
|
||||
rack_count=Count('racks', distinct=True),
|
||||
device_count=Count('devices', distinct=True),
|
||||
vrf_count=Count('vrfs', distinct=True),
|
||||
prefix_count=Count('prefixes', distinct=True),
|
||||
ipaddress_count=Count('ip_addresses', distinct=True),
|
||||
vlan_count=Count('vlans', distinct=True),
|
||||
circuit_count=Count('circuits', distinct=True),
|
||||
), slug=slug)
|
||||
tenant = get_object_or_404(Tenant, slug=slug)
|
||||
stats = {
|
||||
'site_count': Site.objects.filter(tenant=tenant).count(),
|
||||
'rack_count': Rack.objects.filter(tenant=tenant).count(),
|
||||
'device_count': Device.objects.filter(tenant=tenant).count(),
|
||||
'vrf_count': VRF.objects.filter(tenant=tenant).count(),
|
||||
'prefix_count': Prefix.objects.filter(tenant=tenant).count(),
|
||||
'ipaddress_count': IPAddress.objects.filter(tenant=tenant).count(),
|
||||
'vlan_count': VLAN.objects.filter(tenant=tenant).count(),
|
||||
'circuit_count': Circuit.objects.filter(tenant=tenant).count(),
|
||||
}
|
||||
|
||||
return render(request, 'tenancy/tenant.html', {
|
||||
'tenant': tenant,
|
||||
'stats': stats,
|
||||
})
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user