From d0bed830d78ed17a366ef098391ecfc8356c32d7 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 23 Sep 2022 08:12:16 -0700 Subject: [PATCH] 9654 add weight fields to devices --- netbox/dcim/models/mixins.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/netbox/dcim/models/mixins.py b/netbox/dcim/models/mixins.py index 9069f716d..296bacb41 100644 --- a/netbox/dcim/models/mixins.py +++ b/netbox/dcim/models/mixins.py @@ -1,3 +1,4 @@ +from django.core.exceptions import ValidationError from django.db import models from dcim.choices import * from utilities.utils import to_kilograms @@ -35,3 +36,12 @@ class DeviceWeightMixin(models.Model): self._abs_weight = None super().save(*args, **kwargs) + + def clean(self): + super().clean() + + # Validate weight and weight_unit + if self.weight is not None and not self.weight_unit: + raise ValidationError("Must specify a unit when setting a weight") + elif self.weight is None: + self.weight_unit = ''