Skip to content

maykinmedia/django-json-schema-model

Repository files navigation

Version:0.1.0
Source:https://github.com/maykinmedia/django-json-schema-model
Keywords:<keywords>
PythonVersion:3.10

Build status Code quality checks black Coverage status Documentation Status

python-versions django-versions pypi-version

A reusable Django app to store JSON schemas.

  • 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages