Skip to content

Commit c108c73

Browse files
authored
Fixes #18669 - Populate custom field default values (#19115)
1 parent cac41cd commit c108c73

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

netbox/ipam/forms/model_forms.py

-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ def save(self, *args, **kwargs):
538538
role=FHRP_PROTOCOL_ROLE_MAPPINGS.get(self.cleaned_data['protocol'], IPAddressRoleChoices.ROLE_VIP),
539539
assigned_object=instance
540540
)
541-
ipaddress.populate_custom_field_defaults()
542541
ipaddress.save()
543542

544543
# Check that the new IPAddress conforms with any assigned object-level permissions

netbox/netbox/models/features.py

+8
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ def clean(self):
301301
if cf.required and cf.name not in self.custom_field_data:
302302
raise ValidationError(_("Missing required custom field '{name}'.").format(name=cf.name))
303303

304+
def save(self, *args, **kwargs):
305+
# Populate default values if omitted
306+
for cf in self.custom_fields.filter(default__isnull=False):
307+
if cf.name not in self.custom_field_data:
308+
self.custom_field_data[cf.name] = cf.default
309+
310+
super().save(*args, **kwargs)
311+
304312

305313
class CustomLinksMixin(models.Model):
306314
"""

0 commit comments

Comments
 (0)