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

Fixes #12074: Move automatic location assignment out of clean()

* 12074 fix full clean

* 12074 move device location setting to save from clean

* 12074 fix set location only if present in rack

* Update base.py

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
Arthur Hanson 2 лет назад
Родитель
Сommit
2883fa14de
1 измененных файлов с 3 добавлено и 2 удалено
  1. 3 2
      netbox/dcim/models/devices.py

+ 3 - 2
netbox/dcim/models/devices.py

@@ -659,8 +659,6 @@ class Device(PrimaryModel, ConfigContextModel):
             raise ValidationError({
                 'rack': f"Rack {self.rack} does not belong to location {self.location}.",
             })
-        elif self.rack:
-            self.location = self.rack.location
 
         if self.rack is None:
             if self.face:
@@ -801,6 +799,9 @@ class Device(PrimaryModel, ConfigContextModel):
         if is_new and not self.airflow:
             self.airflow = self.device_type.airflow
 
+        if self.rack and self.rack.location:
+            self.location = self.rack.location
+
         super().save(*args, **kwargs)
 
         # If this is a new Device, instantiate all the related components per the DeviceType definition