django-jsonform
django-jsonform copied to clipboard
Add schema validator
I know that this my sound crazy, but I was wondering if somewhere in the source code there is a json schema that validates that the json object/dict used in JSONField(schema=SCHEMA).
My use case is: I want to create a form that is able to output valid json schema forms for this library. Such schemas can later be referenced by other models.
class Schema(models.Model):
name = models.CharField()
schema = JSONField(schema=JSONFORM_SCHEMA)
def get_schema(instance):
if not instance:
return {}
return instance.schema.schema
class AnotherModel(models.Model):
schema = models.ForeignKey('Schema', on_delete=model.PROTECT)
data = JSONField(schema=get_schema, default=dict)
At present there's no validator the schema on the server side. However, the schema does get validated in the browser by the JS component.
But, yes, I agree that we should have a schema validator on the server. I'll try to add this but it may not happen before a couple of weeks.