Closes #17577: Reference ModelState when determining whether an object is being created

This commit is contained in:
Jeremy Stretch
2024-09-23 17:04:18 -04:00
parent d2f42f815f
commit f37e2e55a3
8 changed files with 13 additions and 13 deletions

View File

@@ -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': _(

View File

@@ -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