Version: | 0.1.0 |
---|---|
Source: | https://github.com/maykinmedia/django-json-schema-model |
Keywords: | <keywords> |
PythonVersion: | 3.10 |
A reusable Django app to store JSON schemas.
Contents
- JsonSchemaModel consisting of
- name CharField
- schema JsonField
- validate(json) method to validate JSON against the schema.
- Python 3.10 or above
- Django 4.2 or newer
- A database supporting django.db.models.JSONField
pip install django-json-schema-model
from django_json_schema_model.models import JsonSchema
class ProductType(models.Model):
schema = models.ForeignKey(JsonSchema, on_delete=models.PROTECT)
class Product(models.Model):
json = models.JsonField()
type = models.ForeignKey(ProductType, on_delete=models.CASCADE)
def clean(self):
self.type.schema.validate(self.json)
To install and develop the library locally, use:
.. code-block:: bash
pip install -e .[tests,coverage,docs,release]
When running management commands via django-admin
, make sure to add the root
directory to the python path (or use python -m django <command>
):
export PYTHONPATH=. DJANGO_SETTINGS_MODULE=testapp.settings
django-admin check
# or other commands like:
# django-admin makemessages -l nl