Просмотр исходного кода

Closes #5164: Show total rack count per rack group under site view

Jeremy Stretch 5 лет назад
Родитель
Сommit
e404f4efd2
3 измененных файлов с 9 добавлено и 4 удалено
  1. 1 0
      docs/release-notes/version-2.9.md
  2. 7 3
      netbox/dcim/views.py
  3. 1 1
      netbox/templates/dcim/site.html

+ 1 - 0
docs/release-notes/version-2.9.md

@@ -8,6 +8,7 @@
 * [#5128](https://github.com/netbox-community/netbox/issues/5128) - Increase maximum rear port positions from 64 to 1024
 * [#5128](https://github.com/netbox-community/netbox/issues/5128) - Increase maximum rear port positions from 64 to 1024
 * [#5134](https://github.com/netbox-community/netbox/issues/5134) - Display full hierarchy in breadcrumbs for sites/racks
 * [#5134](https://github.com/netbox-community/netbox/issues/5134) - Display full hierarchy in breadcrumbs for sites/racks
 * [#5149](https://github.com/netbox-community/netbox/issues/5149) - Add rack group field to device edit form
 * [#5149](https://github.com/netbox-community/netbox/issues/5149) - Add rack group field to device edit form
+* [#5164](https://github.com/netbox-community/netbox/issues/5164) - Show total rack count per rack group under site view
 
 
 ### Bug Fixes
 ### Bug Fixes
 
 

+ 7 - 3
netbox/dcim/views.py

@@ -169,9 +169,13 @@ class SiteView(ObjectView):
             'circuit_count': Circuit.objects.restrict(request.user, 'view').filter(terminations__site=site).count(),
             'circuit_count': Circuit.objects.restrict(request.user, 'view').filter(terminations__site=site).count(),
             'vm_count': VirtualMachine.objects.restrict(request.user, 'view').filter(cluster__site=site).count(),
             'vm_count': VirtualMachine.objects.restrict(request.user, 'view').filter(cluster__site=site).count(),
         }
         }
-        rack_groups = RackGroup.objects.restrict(request.user, 'view').filter(site=site).annotate(
-            rack_count=Count('racks')
-        )
+        rack_groups = RackGroup.objects.add_related_count(
+            RackGroup.objects.all(),
+            Rack,
+            'group',
+            'rack_count',
+            cumulative=True
+        ).restrict(request.user, 'view').filter(site=site)
         show_graphs = Graph.objects.filter(type__model='site').exists()
         show_graphs = Graph.objects.filter(type__model='site').exists()
 
 
         return render(request, 'dcim/site.html', {
         return render(request, 'dcim/site.html', {

+ 1 - 1
netbox/templates/dcim/site.html

@@ -255,7 +255,7 @@
             <table class="table table-hover panel-body">
             <table class="table table-hover panel-body">
                 {% for rg in rack_groups %}
                 {% for rg in rack_groups %}
                     <tr>
                     <tr>
-                        <td><i class="fa fa-fw fa-folder-o"></i> <a href="{{ rg.get_absolute_url }}">{{ rg }}</a></td>
+                        <td style="padding-left: {{ rg.level }}8px"><i class="fa fa-fw fa-folder-o"></i> <a href="{{ rg.get_absolute_url }}">{{ rg }}</a></td>
                         <td>{{ rg.rack_count }}</td>
                         <td>{{ rg.rack_count }}</td>
                         <td class="text-right noprint">
                         <td class="text-right noprint">
                             <a href="{% url 'dcim:rack_elevation_list' %}?group_id={{ rg.pk }}" class="btn btn-xs btn-primary" title="View elevations">
                             <a href="{% url 'dcim:rack_elevation_list' %}?group_id={{ rg.pk }}" class="btn btn-xs btn-primary" title="View elevations">