From fddd431d641810fccb10b2945dc2b4cf27afe52b Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Wed, 26 Nov 2025 06:24:11 -0500 Subject: [PATCH 1/2] Add handling for max_cots config option (and configuration.md) --- docs/configuration.md | 7 +++++++ netbox_custom_objects/models.py | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 docs/configuration.md diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 0000000..9c91d04 --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,7 @@ +# Configuration Parameters + +## `max_cots` + +Default: None + +The maximum number of Custom Object Types that may be created. diff --git a/netbox_custom_objects/models.py b/netbox_custom_objects/models.py index 3d117f3..3951113 100644 --- a/netbox_custom_objects/models.py +++ b/netbox_custom_objects/models.py @@ -41,6 +41,7 @@ TagsMixin, get_model_features, ) +from netbox.plugins import get_plugin_config from netbox.registry import registry from netbox.search import SearchIndex from utilities import filters @@ -198,6 +199,7 @@ class CustomObjectType(PrimaryModel): blank=True, editable=False ) + class Meta: verbose_name = "Custom Object Type" ordering = ("name",) @@ -214,6 +216,15 @@ class Meta: def __str__(self): return self.display_name + def clean(self): + super().clean() + + # Enforce max number of COTs that may be created (max_cots) + if not self.pk: + max_cots = get_plugin_config("netbox_custom_objects", "max_cots") + if max_cots and CustomObjectType.objects.count() > max_cots: + raise ValidationError(_(f"Maximum number of Custom Object Types ({max_cots}) exceeded")) + @classmethod def clear_model_cache(cls, custom_object_type_id=None): """ From c942f8b79135e612eadc2c440d67e9e66e1dbc74 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Wed, 26 Nov 2025 17:01:42 -0500 Subject: [PATCH 2/2] Rename to max_custom_object_types --- docs/configuration.md | 2 +- netbox_custom_objects/models.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 9c91d04..6405d24 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,6 +1,6 @@ # Configuration Parameters -## `max_cots` +## `max_custom_object_types` Default: None diff --git a/netbox_custom_objects/models.py b/netbox_custom_objects/models.py index 3951113..9dd087c 100644 --- a/netbox_custom_objects/models.py +++ b/netbox_custom_objects/models.py @@ -219,11 +219,14 @@ def __str__(self): def clean(self): super().clean() - # Enforce max number of COTs that may be created (max_cots) + # Enforce max number of COTs that may be created (max_custom_object_types) if not self.pk: - max_cots = get_plugin_config("netbox_custom_objects", "max_cots") + max_cots = get_plugin_config("netbox_custom_objects", "max_custom_object_types") if max_cots and CustomObjectType.objects.count() > max_cots: - raise ValidationError(_(f"Maximum number of Custom Object Types ({max_cots}) exceeded")) + raise ValidationError(_( + f"Maximum number of Custom Object Types ({max_cots}) " + "exceeded; adjust max_custom_object_types to raise this limit" + )) @classmethod def clear_model_cache(cls, custom_object_type_id=None):