mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-26 18:38:38 -06:00
Schema should be optional
This commit is contained in:
parent
7edc67ed8a
commit
1be9209b04
@ -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()
|
||||
|
@ -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={
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user