Parcourir la source

Fixes #26: Corrected rack validation to work when there are no devices within the rack

Jeremy Stretch il y a 8 ans
Parent
commit
4dd31497e5
1 fichiers modifiés avec 5 ajouts et 4 suppressions
  1. 5 4
      netbox/dcim/models.py

+ 5 - 4
netbox/dcim/models.py

@@ -188,10 +188,11 @@ class Rack(CreatedUpdatedModel):
         # Validate that Rack is tall enough to house the installed Devices
         # Validate that Rack is tall enough to house the installed Devices
         if self.pk:
         if self.pk:
             top_device = Device.objects.filter(rack=self).order_by('-position').first()
             top_device = Device.objects.filter(rack=self).order_by('-position').first()
-            min_height = top_device.position + top_device.device_type.u_height - 1
-            if self.u_height < min_height:
-                raise ValidationError("Rack must be at least {}U tall with currently installed devices."
-                                      .format(min_height))
+            if top_device:
+                min_height = top_device.position + top_device.device_type.u_height - 1
+                if self.u_height < min_height:
+                    raise ValidationError("Rack must be at least {}U tall with currently installed devices."
+                                          .format(min_height))
 
 
     def to_csv(self):
     def to_csv(self):
         return ','.join([
         return ','.join([