mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
Populate omitted custom field default values on save
This commit is contained in:
parent
92317248a3
commit
8cc35eca27
@ -301,6 +301,14 @@ class CustomFieldsMixin(models.Model):
|
|||||||
if cf.required and cf.name not in self.custom_field_data:
|
if cf.required and cf.name not in self.custom_field_data:
|
||||||
raise ValidationError(_("Missing required custom field '{name}'.").format(name=cf.name))
|
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):
|
class CustomLinksMixin(models.Model):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user