9654 add weight fields to devices

This commit is contained in:
Arthur 2022-09-23 10:46:04 -07:00
parent 844a2085b4
commit 61903dbac4
4 changed files with 15 additions and 8 deletions

View File

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

View File

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

View File

@ -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'))
if self._abs_weight:
total_weight += self._abs_weight
return total_weight
return round(total_weight, 2)
class RackReservation(NetBoxModel):

View File

@ -196,7 +196,13 @@
<table class="table table-hover attr-table">
<tr>
<th scope="row">Rack Weight</th>
<td>{{ object.weight }} kg</td>
<td>
{% if object.weight %}
{{ object.weight }}
{% else %}
{{ ''|placeholder }}
{% endif %}
</td>
</tr>
<tr>
<th scope="row">Total Weight</th>