Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Configuration Parameters

## `max_custom_object_types`

Default: None

The maximum number of Custom Object Types that may be created.
14 changes: 14 additions & 0 deletions netbox_custom_objects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -198,6 +199,7 @@ class CustomObjectType(PrimaryModel):
blank=True,
editable=False
)

class Meta:
verbose_name = "Custom Object Type"
ordering = ("name",)
Expand All @@ -214,6 +216,18 @@ class Meta:
def __str__(self):
return self.display_name

def clean(self):
super().clean()

# 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_custom_object_types")
if max_cots and CustomObjectType.objects.count() > max_cots:
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):
"""
Expand Down