Skip to main content

JSON Schema forms for Django

Project description

django-jsonforms provides the JSONSchemaField which renders a dynamic form from a json schema using json-editor (https://github.com/jdorn/json-editor) The field also validates submitted data against the json schema

Installation

pip install git+https://github.com/Aristotle-Metadata-Enterprises/django-jsonforms#egg=django-jsonforms

Add ‘django_jsonforms’ to your INSTALLED_APPS

Requirements

The python requirements jsonschema and django will be installed when installing the package through pipAdditionally jQuery is required on the page that will be rendering the form. Instructions for adding jQuery here: https://www.w3schools.com/jquery/jquery_get_started.asp

Usage

The field can be used like any other Django form field, it has the schema and options attributes which can be either python dictionaries or paths to staticfiles as as shown belowThe schema parameter is the json schema the field will useThe options parameter is passed through to the json-editor object, these options are described here: https://github.com/jdorn/json-editor#options (the schema option is not used)An optional ajax parameter determines whether any files are loaded via ajax on the frontend or loaded in the backend and put into html parameters (defaults to true)

Example:

from django.forms import ModelForm, Form
from django_jsonforms.forms import JSONSchemaField

class RegistrySettingsForm(Form):

    json = JSONSchemaField(
        schema = 'schema/schema.json',
        options = 'schema/options.json'
    )

In this example the schema file would be located in ‘static/schema/schema.json’. You will need to run collectstatic after creating the file

Example showing all options:

class RegistrySettingsForm(Form):

    json = JSONSchemaField(
        schema = 'schema/schema.json',
        options = {"theme": "bootstrap3"},
        ajax = false
    )

Since it is common to have only one field in this type of form. A form with a single JSONSchemaField named json is also available to use

Form Example::

from django_jsonforms.forms import JSONSchemaForm

form = JSONSchemaForm(schema=… , options=… , ajax=…)

Note:

When rendering the form don’t forget to render the forms media with the template tag {{ form.media }}. This is required for the field to function correctly

The data returned when the field is submitted is in the form of a python dictionary. This may need to be converted before being stored depending on the model field being used

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-jsonforms-1.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

django_jsonforms-1.0.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file django-jsonforms-1.0.0.tar.gz.

File metadata

File hashes

Hashes for django-jsonforms-1.0.0.tar.gz
Algorithm Hash digest
SHA256 80fa8ae29a0f64c0a3453feed8de3e2e322b056953b2cc9a7fed01fa462bc28b
MD5 b37b92634d6fe706ee45062568f8768c
BLAKE2b-256 be3cb244587945a39e3a5823a31866193fe6a99f85e9a02155b534abab17a30d

See more details on using hashes here.

File details

Details for the file django_jsonforms-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_jsonforms-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73f7e38b4b30251521046ea3dc87684fb98e983522ec003cd46b9a7aabcb87fa
MD5 456a2dc892d1259a119bf3052da90dfa
BLAKE2b-256 c33dbb6924f75ab6ca914e2eec5fc2dca3ac64713c551c7a2ec45e157a7521b2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page