From 559a318584d0224cd014f5f6d3d3b34d3298af5e Mon Sep 17 00:00:00 2001 From: Simon Toft Date: Fri, 10 Feb 2023 12:19:44 +0100 Subject: [PATCH] Fixes #11565 - Populate custom field defaults when creating FHRP groups with VIP --- netbox/ipam/forms/model_forms.py | 1 + netbox/netbox/models/features.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/netbox/ipam/forms/model_forms.py b/netbox/ipam/forms/model_forms.py index 430a4b2f8..a34222479 100644 --- a/netbox/ipam/forms/model_forms.py +++ b/netbox/ipam/forms/model_forms.py @@ -578,6 +578,7 @@ 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 diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py index f041d016d..62482a26f 100644 --- a/netbox/netbox/models/features.py +++ b/netbox/netbox/models/features.py @@ -216,6 +216,13 @@ class CustomFieldsMixin(models.Model): return dict(groups) + def populate_custom_field_defaults(self): + """ + Apply the default value for each custom field + """ + for cf in self.custom_fields: + self.custom_field_data[cf.name] = cf.default + def clean(self): super().clean() from extras.models import CustomField