mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Standardize related model display for organizational models
This commit is contained in:
committed by
jeremystretch
parent
91b81d51da
commit
94797bb956
@@ -10,7 +10,7 @@ from dcim.models import Device
|
||||
from dcim.tables import DeviceTable
|
||||
from extras.views import ObjectConfigContextView
|
||||
from ipam.models import IPAddress, Service
|
||||
from ipam.tables import AssignedIPAddressesTable, InterfaceVLANTable
|
||||
from ipam.tables import InterfaceVLANTable
|
||||
from netbox.views import generic
|
||||
from utilities.utils import count_related
|
||||
from utilities.views import ViewTab, register_model_view
|
||||
@@ -36,17 +36,12 @@ class ClusterTypeView(generic.ObjectView):
|
||||
queryset = ClusterType.objects.all()
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
clusters = Cluster.objects.restrict(request.user, 'view').filter(
|
||||
type=instance
|
||||
).annotate(
|
||||
device_count=count_related(Device, 'cluster'),
|
||||
vm_count=count_related(VirtualMachine, 'cluster')
|
||||
related_models = (
|
||||
(Cluster.objects.restrict(request.user, 'view').filter(type=instance), 'type_id'),
|
||||
)
|
||||
clusters_table = tables.ClusterTable(clusters, user=request.user, exclude=('type',))
|
||||
clusters_table.configure(request)
|
||||
|
||||
return {
|
||||
'clusters_table': clusters_table,
|
||||
'related_models': related_models,
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +95,15 @@ class ClusterGroupListView(generic.ObjectListView):
|
||||
class ClusterGroupView(generic.ObjectView):
|
||||
queryset = ClusterGroup.objects.all()
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
related_models = (
|
||||
(Cluster.objects.restrict(request.user, 'view').filter(group=instance), 'group_id'),
|
||||
)
|
||||
|
||||
return {
|
||||
'related_models': related_models,
|
||||
}
|
||||
|
||||
|
||||
@register_model_view(ClusterGroup, 'edit')
|
||||
class ClusterGroupEditView(generic.ObjectEditView):
|
||||
|
Reference in New Issue
Block a user