diff --git a/netbox/dcim/tables/sites.py b/netbox/dcim/tables/sites.py index e8cb9140e..5206bb755 100644 --- a/netbox/dcim/tables/sites.py +++ b/netbox/dcim/tables/sites.py @@ -146,6 +146,11 @@ class LocationTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable): url_params={'location_id': 'pk'}, verbose_name=_('Devices') ) + vlangroup_count = columns.LinkedCountColumn( + viewname='ipam:vlangroup_list', + url_params={'location': 'pk'}, + verbose_name=_('VLAN Groups') + ) tags = columns.TagColumn( url_name='dcim:location_list' ) @@ -157,8 +162,9 @@ class LocationTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable): model = Location fields = ( 'pk', 'id', 'name', 'site', 'status', 'facility', 'tenant', 'tenant_group', 'rack_count', 'device_count', - 'description', 'slug', 'contacts', 'tags', 'actions', 'created', 'last_updated', + 'description', 'slug', 'contacts', 'tags', 'actions', 'created', 'last_updated', 'vlangroup_count', ) default_columns = ( - 'pk', 'name', 'site', 'status', 'facility', 'tenant', 'rack_count', 'device_count', 'description' + 'pk', 'name', 'site', 'status', 'facility', 'tenant', 'rack_count', 'device_count', 'vlangroup_count', + 'description' ) diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 60de8c355..f63a0ad79 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -505,18 +505,24 @@ class SiteContactsView(ObjectContactsView): @register_model_view(Location, 'list', path='', detail=False) class LocationListView(generic.ObjectListView): queryset = Location.objects.add_related_count( - Location.objects.add_related_count( - Location.objects.all(), - Device, - 'location', - 'device_count', - cumulative=True - ), - Rack, - 'location', - 'rack_count', - cumulative=True - ) + Location.objects.add_related_count( + Location.objects.add_related_count( + Location.objects.all(), + Device, + 'location', + 'device_count', + cumulative=True + ), + Rack, + 'location', + 'rack_count', + cumulative=True + ), + VLANGroup, + 'location', + 'vlangroup_count', + cumulative=True + ) filterset = filtersets.LocationFilterSet filterset_form = forms.LocationFilterForm table = tables.LocationTable @@ -528,6 +534,7 @@ class LocationView(GetRelatedModelsMixin, generic.ObjectView): def get_extra_context(self, request, instance): locations = instance.get_descendants(include_self=True) + location_content_type = ContentType.objects.get_for_model(instance) return { 'related_models': self.get_related_models( request, @@ -545,6 +552,8 @@ class LocationView(GetRelatedModelsMixin, generic.ObjectView): (Cluster.objects.restrict(request.user, 'view').filter(_location=instance), 'location_id'), (Prefix.objects.restrict(request.user, 'view').filter(_location=instance), 'location_id'), (WirelessLAN.objects.restrict(request.user, 'view').filter(_location=instance), 'location_id'), + (VLANGroup.objects.restrict(request.user, 'view').filter( + scope_type_id=location_content_type.id, scope_id=instance.id), 'location'), ), ), }