From 844a2085b4a384ba968c3d650cd6aa192c63e428 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 23 Sep 2022 10:35:34 -0700 Subject: [PATCH] 9654 add weight fields to devices --- netbox/dcim/models/racks.py | 2 +- netbox/templates/dcim/rack.html | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index 0a34681e0..f69d4f21d 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -452,7 +452,7 @@ class Rack(NetBoxModel, DeviceWeightMixin): def get_total_weight(self): total_weight = sum(device.device_type._abs_weight for device in self.devices.exclude(device_type___abs_weight__isnull=True).prefetch_related('device_type')) - total_weight += sum(module.module_type._abs_weight for module in Module.objects.filter(device=self).exclude(module_type___abs_weight__isnull=True).prefetch_related('module_type')) + total_weight += sum(module.module_type._abs_weight for module in Module.objects.filter(device__rack=self).exclude(module_type___abs_weight__isnull=True).prefetch_related('module_type')) total_weight += self._abs_weight return total_weight diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index 51e873ffa..d19ca80ae 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -186,6 +186,27 @@ {% endif %} + + {% if object.get_total_weight %} +
+
+ Weight +
+
+ + + + + + + + + +
Rack Weight{{ object.weight }} kg
Total Weight{{ object.get_total_weight }} kg
+
+
+ {% endif %} + {% include 'inc/panels/image_attachments.html' %}