From 8cc35eca2725965c58b6caa7b382560c08e5adb3 Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:31:04 -0500 Subject: [PATCH] Populate omitted custom field default values on save --- netbox/netbox/models/features.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py index a97227770..b58d232cd 100644 --- a/netbox/netbox/models/features.py +++ b/netbox/netbox/models/features.py @@ -301,6 +301,14 @@ class CustomFieldsMixin(models.Model): if cf.required and cf.name not in self.custom_field_data: raise ValidationError(_("Missing required custom field '{name}'.").format(name=cf.name)) + def save(self, *args, **kwargs): + # Populate default values if omitted + for cf in self.custom_fields.filter(default__isnull=False): + if cf.name not in self.custom_field_data: + self.custom_field_data[cf.name] = cf.default + + super().save(*args, **kwargs) + class CustomLinksMixin(models.Model): """