Просмотр исходного кода

Fixes #5218: Raise validation error if a power port's allocated_draw exceeds its maximum_draw

Jeremy Stretch 5 лет назад
Родитель
Сommit
39e4ab164e
2 измененных файлов с 9 добавлено и 0 удалено
  1. 1 0
      docs/release-notes/version-2.9.md
  2. 8 0
      netbox/dcim/models/device_components.py

+ 1 - 0
docs/release-notes/version-2.9.md

@@ -13,6 +13,7 @@
 * [#5201](https://github.com/netbox-community/netbox/issues/5201) - Fix missing querystring when bulk editing/deleting VLAN Group VLANs when selecting "select all x items matching query"
 * [#5206](https://github.com/netbox-community/netbox/issues/5206) - Apply user pagination preferences to all paginated object lists
 * [#5217](https://github.com/netbox-community/netbox/issues/5217) - Prevent erroneous removal of prefetched GenericForeignKey data from tables
+* [#5218](https://github.com/netbox-community/netbox/issues/5218) - Raise validation error if a power port's `allocated_draw` exceeds its `maximum_draw`
 
 ---
 

+ 8 - 0
netbox/dcim/models/device_components.py

@@ -405,6 +405,14 @@ class PowerPort(CableTermination, ComponentModel):
             self.description,
         )
 
+    def clean(self):
+
+        if self.maximum_draw is not None and self.allocated_draw is not None:
+            if self.allocated_draw > self.maximum_draw:
+                raise ValidationError({
+                    'allocated_draw': f"Allocated draw cannot exceed the maximum draw ({self.maximum_draw}W)."
+                })
+
     @property
     def connected_endpoint(self):
         """