1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
netbox-community-netbox/netbox/extras/migrations/0066_customfield_name_validation.py
Arthur Hanson 21f4761335 12468 disallow double underscores in custom field names (#12523)
* 12468 disallow double underscores in custom field names

* 12468 disallow double underscores in custom field names

* 12468 review changes

* 12468 correct migration

* 12468 use inverse match

* 12468 use inverse match

* Add test for invalid custom field names

---------

Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
2023-05-12 16:08:57 -04:00

35 lines
1.1 KiB
Python

import django.core.validators
from django.db import migrations, models
import re
class Migration(migrations.Migration):
dependencies = [
('extras', '0065_imageattachment_change_logging'),
]
operations = [
migrations.AlterField(
model_name='customfield',
name='name',
field=models.CharField(
max_length=50,
unique=True,
validators=[
django.core.validators.RegexValidator(
flags=re.RegexFlag['IGNORECASE'],
message='Only alphanumeric characters and underscores are allowed.',
regex='^[a-z0-9_]+$',
),
django.core.validators.RegexValidator(
flags=re.RegexFlag['IGNORECASE'],
inverse_match=True,
message='Double underscores are not permitted in custom field names.',
regex=r'__',
),
],
),
),
]