Ver Fonte

Fixes #18669 - Populate custom field default values (#19115)

atownson há 10 meses atrás
pai
commit
c108c738ae
2 ficheiros alterados com 8 adições e 1 exclusões
  1. 0 1
      netbox/ipam/forms/model_forms.py
  2. 8 0
      netbox/netbox/models/features.py

+ 0 - 1
netbox/ipam/forms/model_forms.py

@@ -538,7 +538,6 @@ class FHRPGroupForm(NetBoxModelForm):
                 role=FHRP_PROTOCOL_ROLE_MAPPINGS.get(self.cleaned_data['protocol'], IPAddressRoleChoices.ROLE_VIP),
                 assigned_object=instance
             )
-            ipaddress.populate_custom_field_defaults()
             ipaddress.save()
 
             # Check that the new IPAddress conforms with any assigned object-level permissions

+ 8 - 0
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):
     """