jeremystretch 4 лет назад
Родитель
Сommit
7b8bd2d4ce

+ 2 - 1
netbox/dcim/api/serializers.py

@@ -134,12 +134,13 @@ class LocationSerializer(NestedGroupModelSerializer):
     site = NestedSiteSerializer()
     parent = NestedLocationSerializer(required=False, allow_null=True)
     rack_count = serializers.IntegerField(read_only=True)
+    device_count = serializers.IntegerField(read_only=True)
 
     class Meta:
         model = Location
         fields = [
             'id', 'url', 'display', 'name', 'slug', 'site', 'parent', 'description', 'custom_fields', 'created',
-            'last_updated', 'rack_count', '_depth',
+            'last_updated', 'rack_count', 'device_count', '_depth',
         ]
 
 

+ 8 - 2
netbox/dcim/api/views.py

@@ -146,7 +146,13 @@ class SiteViewSet(CustomFieldModelViewSet):
 
 class LocationViewSet(CustomFieldModelViewSet):
     queryset = Location.objects.add_related_count(
-        Location.objects.all(),
+        Location.objects.add_related_count(
+            Location.objects.all(),
+            Device,
+            'location',
+            'device_count',
+            cumulative=True
+        ),
         Rack,
         'location',
         'rack_count',
@@ -174,7 +180,7 @@ class RackRoleViewSet(CustomFieldModelViewSet):
 
 class RackViewSet(CustomFieldModelViewSet):
     queryset = Rack.objects.prefetch_related(
-        'site', 'location__site', 'role', 'tenant', 'tags'
+        'site', 'location', 'role', 'tenant', 'tags'
     ).annotate(
         device_count=count_related(Device, 'rack'),
         powerfeed_count=count_related(PowerFeed, 'rack')

+ 1 - 0
netbox/dcim/models/sites.py

@@ -315,6 +315,7 @@ class Location(NestedGroupModel):
     )
 
     csv_headers = ['site', 'parent', 'name', 'slug', 'description']
+    clone_fields = ['site', 'parent', 'description']
 
     class Meta:
         ordering = ['site', 'name']

+ 7 - 0
netbox/dcim/views.py

@@ -272,6 +272,13 @@ class SiteView(generic.ObjectView):
             'location',
             'rack_count',
             cumulative=True
+        )
+        locations = Location.objects.add_related_count(
+            locations,
+            Device,
+            'location',
+            'device_count',
+            cumulative=True
         ).restrict(request.user, 'view').filter(site=instance)
 
         return {

+ 4 - 0
netbox/templates/dcim/location.html

@@ -26,6 +26,10 @@
           <td>Description</td>
           <td>{{ object.description|placeholder }}</td>
         </tr>
+        <tr>
+          <td>Site</td>
+          <td><a href="{{ object.site.get_absolute_url }}">{{ object.site }}</a></td>
+        </tr>
         <tr>
           <td>Parent</td>
           <td>

+ 12 - 11
netbox/templates/dcim/site.html

@@ -210,12 +210,22 @@
                 <strong>Locations</strong>
             </div>
             <table class="table table-hover panel-body">
+                <tr>
+                    <th>Location</th>
+                    <th>Racks</th>
+                    <th>Devices</th>
+                    <th></th>
+                </tr>
                 {% for location in locations %}
                     <tr>
                         <td style="padding-left: {{ location.level }}8px">
-                          <i class="mdi mdi-folder-open"></i> <a href="{{ location.get_absolute_url }}">{{ location }}</a>
+                          <i class="mdi mdi-folder-open-outline"></i> <a href="{{ location.get_absolute_url }}">{{ location }}</a>
+                        </td>
+                        <td>
+                          <a href="{% url 'dcim:rack_list' %}?location_id={{ location.pk }}">{{ location.rack_count }}</a></td>
+                        <td>
+                          <a href="{% url 'dcim:device_list' %}?location_id={{ location.pk }}">{{ location.device_count }}</a>
                         </td>
-                        <td>{{ location.rack_count }}</td>
                         <td class="text-right noprint">
                             <a href="{% url 'dcim:rack_elevation_list' %}?location_id={{ location.pk }}" class="btn btn-xs btn-primary" title="View elevations">
                                 <i class="mdi mdi-server"></i>
@@ -223,15 +233,6 @@
                         </td>
                     </tr>
                 {% endfor %}
-                <tr>
-                    <td><i class="mdi mdi-folder-open"></i> All racks</td>
-                    <td>{{ stats.rack_count }}</td>
-                    <td class="text-right noprint">
-                        <a href="{% url 'dcim:rack_elevation_list' %}?site_id={{ object.pk }}" class="btn btn-xs btn-primary" title="View elevations">
-                            <i class="mdi mdi-server"></i>
-                        </a>
-                    </td>
-                </tr>
             </table>
         </div>
         <div class="panel panel-default">