Schema should be optional

This commit is contained in:
Jeremy Stretch 2025-03-28 15:20:27 -04:00
parent 7edc67ed8a
commit 1be9209b04
3 changed files with 11 additions and 7 deletions

View File

@ -409,6 +409,7 @@ class DeviceTypeForm(NetBoxModelForm):
class ModuleTypeProfileForm(NetBoxModelForm):
schema = JSONField(
label=_('Schema'),
required=False,
help_text=_("Enter a valid JSON schema to define supported attributes.")
)
comments = CommentField()

View File

@ -25,7 +25,7 @@ class Migration(migrations.Migration):
('description', models.CharField(blank=True, max_length=200)),
('comments', models.TextField(blank=True)),
('name', models.CharField(max_length=100, unique=True)),
('schema', models.JSONField()),
('schema', models.JSONField(blank=True, null=True)),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={

View File

@ -33,6 +33,8 @@ class ModuleTypeProfile(PrimaryModel):
unique=True
)
schema = models.JSONField(
blank=True,
null=True,
verbose_name=_('schema')
)
@ -50,12 +52,13 @@ class ModuleTypeProfile(PrimaryModel):
super().clean()
# Validate the schema definition
try:
JSONSchemaValidator.check_schema(self.schema)
except SchemaError as e:
raise ValidationError({
'schema': _("Invalid schema: {error}").format(error=e)
})
if self.schema:
try:
JSONSchemaValidator.check_schema(self.schema)
except SchemaError as e:
raise ValidationError({
'schema': _("Invalid schema: {error}").format(error=e)
})
class ModuleType(ImageAttachmentsMixin, PrimaryModel, WeightMixin):