mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-19 11:52:22 -06:00
Closes #17577: Reference ModelState when determining whether an object is being created
This commit is contained in:
@@ -134,7 +134,7 @@ class Cluster(ContactsMixin, PrimaryModel):
|
||||
super().clean()
|
||||
|
||||
# If the Cluster is assigned to a Site, verify that all host Devices belong to that Site.
|
||||
if self.pk and self.site:
|
||||
if not self._state.adding and self.site:
|
||||
if nonsite_devices := Device.objects.filter(cluster=self).exclude(site=self.site).count():
|
||||
raise ValidationError({
|
||||
'site': _(
|
||||
|
||||
@@ -205,7 +205,7 @@ class VirtualMachine(ContactsMixin, ImageAttachmentsMixin, RenderConfigMixin, Co
|
||||
})
|
||||
|
||||
# Validate aggregate disk size
|
||||
if self.pk:
|
||||
if not self._state.adding:
|
||||
total_disk = self.virtualdisks.aggregate(Sum('size', default=0))['size__sum']
|
||||
if total_disk and self.disk is None:
|
||||
self.disk = total_disk
|
||||
|
||||
Reference in New Issue
Block a user