I have a django model with a JSONField
(django.contrib.postgres.fields.JSONField)
Is there any way that I can validate model data against a json schema file?
(pre-save)
Something like my_field = JSONField(schema_file=my_schema_file)
I have a django model with a JSONField
(django.contrib.postgres.fields.JSONField)
Is there any way that I can validate model data against a json schema file?
(pre-save)
Something like my_field = JSONField(schema_file=my_schema_file)
you could use cerberus to validate your data against a schema
it's pretty straightforward to use (also due to it's good documentation -> validation rules: http://docs.python-cerberus.org/en/stable/validation-rules.html)
I wrote a custom validator using
jsonschema
in order to do this (Django 1.11, Python 3.6).project/validators.py
project/app/models.py
That's what the
Model.clean()
method is for (see docs). Example: