diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index b0d4f7e4e..9312c2ce0 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -7,6 +7,7 @@ * [#6179](https://github.com/netbox-community/netbox/issues/6179) - Enable natural ordering for virtual machines * [#6189](https://github.com/netbox-community/netbox/issues/6189) - Add ability to search for locations by name or description * [#6190](https://github.com/netbox-community/netbox/issues/6190) - Allow filtering devices with no location assigned +* [#6210](https://github.com/netbox-community/netbox/issues/6210) - Include child locations on location view ### Bug Fixes diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 5da50e0db..7f0d6d4c3 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -364,16 +364,30 @@ class LocationView(generic.ObjectView): queryset = Location.objects.all() def get_extra_context(self, request, instance): - devices = Device.objects.restrict(request.user, 'view').filter( - location=instance - ) + location_ids = instance.get_descendants(include_self=True).values_list('pk', flat=True) + rack_count = Rack.objects.filter(location__in=location_ids).count() + device_count = Device.objects.filter(location__in=location_ids).count() - devices_table = tables.DeviceTable(devices) - devices_table.columns.hide('location') - paginate_table(devices_table, request) + child_locations = 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 + ).filter(pk__in=location_ids).exclude(pk=instance.pk) + child_locations_table = tables.LocationTable(child_locations) + paginate_table(child_locations_table, request) return { - 'devices_table': devices_table, + 'rack_count': rack_count, + 'device_count': device_count, + 'child_locations_table': child_locations_table, } diff --git a/netbox/templates/dcim/location.html b/netbox/templates/dcim/location.html index a5eeb4e71..e523465ec 100644 --- a/netbox/templates/dcim/location.html +++ b/netbox/templates/dcim/location.html @@ -43,13 +43,13 @@