9654 add weight fields to devices

This commit is contained in:
Arthur 2022-09-23 10:35:34 -07:00
parent a869720cca
commit 844a2085b4
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -186,6 +186,27 @@
</div>
</div>
{% endif %}
{% if object.get_total_weight %}
<div class="card">
<h5 class="card-header">
Weight
</h5>
<div class="card-body">
<table class="table table-hover attr-table">
<tr>
<th scope="row">Rack Weight</th>
<td>{{ object.weight }} kg</td>
</tr>
<tr>
<th scope="row">Total Weight</th>
<td>{{ object.get_total_weight }} kg</td>
</tr>
</table>
</div>
</div>
{% endif %}
{% include 'inc/panels/image_attachments.html' %}
<div class="card">
<h5 class="card-header">