1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #8030: Validate custom field names

This commit is contained in:
jeremystretch
2021-12-09 15:19:19 -05:00
parent 1df05715c2
commit de698154cd
4 changed files with 34 additions and 2 deletions

View File

@ -22,6 +22,12 @@ from utilities.querysets import RestrictedQuerySet
from utilities.validators import validate_regex
__all__ = (
'CustomField',
'CustomFieldManager',
)
class CustomFieldManager(models.Manager.from_queryset(RestrictedQuerySet)):
use_in_migrations = True
@ -49,7 +55,14 @@ class CustomField(ChangeLoggedModel):
name = models.CharField(
max_length=50,
unique=True,
help_text='Internal field name'
help_text='Internal field name',
validators=(
RegexValidator(
regex=r'^[a-z0-9_]+$',
message="Only alphanumeric characters and underscores are allowed.",
flags=re.IGNORECASE
),
)
)
label = models.CharField(
max_length=50,