diff --git a/netbox/dcim/migrations/0162_devicetype__abs_weight_devicetype_weight_and_more.py b/netbox/dcim/migrations/0162_devicetype__abs_weight_devicetype_weight_and_more.py index 14e2c9475..1e46b5790 100644 --- a/netbox/dcim/migrations/0162_devicetype__abs_weight_devicetype_weight_and_more.py +++ b/netbox/dcim/migrations/0162_devicetype__abs_weight_devicetype_weight_and_more.py @@ -13,7 +13,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='devicetype', name='_abs_weight', - field=models.DecimalField(blank=True, decimal_places=4, max_digits=10, null=True), + field=models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True), ), migrations.AddField( model_name='devicetype', @@ -28,7 +28,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='moduletype', name='_abs_weight', - field=models.DecimalField(blank=True, decimal_places=4, max_digits=10, null=True), + field=models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True), ), migrations.AddField( model_name='moduletype', @@ -43,7 +43,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='rack', name='_abs_weight', - field=models.DecimalField(blank=True, decimal_places=4, max_digits=10, null=True), + field=models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True), ), migrations.AddField( model_name='rack', diff --git a/netbox/dcim/models/mixins.py b/netbox/dcim/models/mixins.py index 296bacb41..4655c1ec3 100644 --- a/netbox/dcim/models/mixins.py +++ b/netbox/dcim/models/mixins.py @@ -16,10 +16,10 @@ class DeviceWeightMixin(models.Model): choices=DeviceWeightUnitChoices, blank=True, ) - # Stores the normalized length (in meters) for database ordering + # Stores the normalized weight (in kilograms) for database ordering _abs_weight = models.DecimalField( max_digits=10, - decimal_places=4, + decimal_places=2, blank=True, null=True ) diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index f69d4f21d..bc3a52772 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -453,8 +453,9 @@ 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__rack=self).exclude(module_type___abs_weight__isnull=True).prefetch_related('module_type')) - total_weight += self._abs_weight - return total_weight + if self._abs_weight: + total_weight += self._abs_weight + return round(total_weight, 2) class RackReservation(NetBoxModel): diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index d19ca80ae..acd72a5d1 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -196,7 +196,13 @@ - +
Rack Weight{{ object.weight }} kg + {% if object.weight %} + {{ object.weight }} + {% else %} + {{ ''|placeholder }} + {% endif %} +
Total Weight