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

Clean up CustomField regex validation

This commit is contained in:
Jeremy Stretch
2020-11-10 10:21:18 -05:00
parent b8a7870750
commit 3d6bf1e0f8
2 changed files with 14 additions and 3 deletions

View File

@ -75,6 +75,14 @@ class CustomFieldForm(forms.ModelForm):
class Meta:
model = CustomField
exclude = []
widgets = {
'validation_regex': forms.Textarea(
attrs={
'cols': 80,
'rows': 3,
}
)
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -109,7 +117,8 @@ class CustomFieldAdmin(admin.ModelAdmin):
'fields': ('content_types',)
}),
('Validation Rules', {
'fields': ('validation_minimum', 'validation_maximum', 'validation_regex')
'fields': ('validation_minimum', 'validation_maximum', 'validation_regex'),
'classes': ('monospace',)
}),
('Choices', {
'description': 'A selection field must have two or more choices assigned to it.',

View File

@ -70,7 +70,8 @@ class CustomField(models.Model):
)
name = models.CharField(
max_length=50,
unique=True
unique=True,
help_text='Internal field name'
)
label = models.CharField(
max_length=50,
@ -120,7 +121,8 @@ class CustomField(models.Model):
validators=[validate_regex],
max_length=500,
verbose_name='Validation regex',
help_text='Regular expression to enforce on text field values'
help_text='Regular expression to enforce on text field values. Use ^ and $ to force matching of entire string. '
'For example, <code>^[A-Z]{3}$</code> will limit values to exactly three uppercase letters.'
)
choices = ArrayField(
base_field=models.CharField(max_length=100),