mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-07 16:18:16 -06:00
Clone device site and location from rack
When a device is assigned to a rack, its site and location are cloned from the rack regardless of user input. This also allows some consistency checks to be removed, as inconsistent data would still be overwritten with valid values when saving the Device object.
This commit is contained in:
parent
65f81ab81d
commit
fd309a0003
@ -829,23 +829,13 @@ class Device(
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
# Validate site/location/rack combination
|
# Validate site/location combination
|
||||||
if self.rack and self.site != self.rack.site:
|
|
||||||
raise ValidationError({
|
|
||||||
'rack': _("Rack {rack} does not belong to site {site}.").format(rack=self.rack, site=self.site),
|
|
||||||
})
|
|
||||||
if self.location and self.site != self.location.site:
|
if self.location and self.site != self.location.site:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'location': _(
|
'location': _(
|
||||||
"Location {location} does not belong to site {site}."
|
"Location {location} does not belong to site {site}."
|
||||||
).format(location=self.location, site=self.site)
|
).format(location=self.location, site=self.site)
|
||||||
})
|
})
|
||||||
if self.rack and self.location and self.rack.location != self.location:
|
|
||||||
raise ValidationError({
|
|
||||||
'rack': _(
|
|
||||||
"Rack {rack} does not belong to location {location}."
|
|
||||||
).format(rack=self.rack, location=self.location)
|
|
||||||
})
|
|
||||||
|
|
||||||
if self.rack is None:
|
if self.rack is None:
|
||||||
if self.face:
|
if self.face:
|
||||||
@ -1031,8 +1021,9 @@ class Device(
|
|||||||
if is_new and not self.platform:
|
if is_new and not self.platform:
|
||||||
self.platform = self.device_type.default_platform
|
self.platform = self.device_type.default_platform
|
||||||
|
|
||||||
# Inherit location from Rack if not set
|
# Inherit site/location from Rack
|
||||||
if self.rack and self.rack.location:
|
if self.rack:
|
||||||
|
self.site = self.rack.site
|
||||||
self.location = self.rack.location
|
self.location = self.rack.location
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user