1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add group and site matching validation to Rack.clean() and testing

This commit is contained in:
Ryan Breaker
2017-10-15 18:35:03 -05:00
parent 34259d5d9d
commit 115e7d6e50
2 changed files with 40 additions and 6 deletions

View File

@@ -256,8 +256,8 @@ class Rack(CreatedUpdatedModel, CustomFieldModel):
def clean(self):
# Validate that Rack is tall enough to house the installed Devices
if self.pk:
# Validate that Rack is tall enough to house the installed Devices
top_device = Device.objects.filter(rack=self).exclude(position__isnull=True).order_by('-position').first()
if top_device:
min_height = top_device.position + top_device.device_type.u_height - 1
@@ -267,6 +267,12 @@ class Rack(CreatedUpdatedModel, CustomFieldModel):
min_height
)
})
# Validate that Rack was assigned a group of its same site, if applicable
if self.group:
if self.group.site != self.site:
raise ValidationError({
'group': "Rack group must be from the same site, {}.".format(self.site)
})
def save(self, *args, **kwargs):