mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merge branch 'feature' into 9071-plugin-menu
This commit is contained in:
@@ -955,12 +955,13 @@ class RearPort(ModularComponentModel, CabledObjectModel):
|
||||
super().clean()
|
||||
|
||||
# Check that positions count is greater than or equal to the number of associated FrontPorts
|
||||
frontport_count = self.frontports.count()
|
||||
if self.positions < frontport_count:
|
||||
raise ValidationError({
|
||||
"positions": f"The number of positions cannot be less than the number of mapped front ports "
|
||||
f"({frontport_count})"
|
||||
})
|
||||
if self.pk:
|
||||
frontport_count = self.frontports.count()
|
||||
if self.positions < frontport_count:
|
||||
raise ValidationError({
|
||||
"positions": f"The number of positions cannot be less than the number of mapped front ports "
|
||||
f"({frontport_count})"
|
||||
})
|
||||
|
||||
|
||||
#
|
||||
|
@@ -268,7 +268,7 @@ class DeviceType(NetBoxModel):
|
||||
|
||||
if (
|
||||
self.subdevice_role != SubdeviceRoleChoices.ROLE_PARENT
|
||||
) and self.devicebaytemplates.count():
|
||||
) and self.pk and self.devicebaytemplates.count():
|
||||
raise ValidationError({
|
||||
'subdevice_role': "Must delete all device bay templates associated with this device before "
|
||||
"declassifying it as a parent device."
|
||||
|
@@ -92,8 +92,17 @@ class CloningMixin(models.Model):
|
||||
|
||||
def clone(self):
|
||||
"""
|
||||
Return a dictionary of attributes suitable for creating a copy of the current instance. This is used for pre-
|
||||
populating an object creation form in the UI.
|
||||
Returns a dictionary of attributes suitable for creating a copy of the current instance. This is used for pre-
|
||||
populating an object creation form in the UI. By default, this method will replicate any fields listed in the
|
||||
model's `clone_fields` list (if defined), but it can be overridden to apply custom logic.
|
||||
|
||||
```python
|
||||
class MyModel(NetBoxModel):
|
||||
def clone(self):
|
||||
attrs = super().clone()
|
||||
attrs['extra-value'] = 123
|
||||
return attrs
|
||||
```
|
||||
"""
|
||||
attrs = {}
|
||||
|
||||
|
@@ -367,7 +367,7 @@ class VirtualMachine(NetBoxModel, ConfigContextModel):
|
||||
})
|
||||
|
||||
# Validate primary IP addresses
|
||||
interfaces = self.interfaces.all()
|
||||
interfaces = self.interfaces.all() if self.pk else None
|
||||
for family in (4, 6):
|
||||
field = f'primary_ip{family}'
|
||||
ip = getattr(self, field)
|
||||
|
Reference in New Issue
Block a user