Quickstart

django-jsonform allows you to edit JSON data by supplying a schema for the data structure.

Shopping list

Suppose we want to create a model for saving shopping lists. A typical shopping list looks like this: ['eggs', 'milk', 'juice']. It is basically a list of strings.

Sample model

django-jsonform provides a custom JSONField for your convenience. You can also use the widget but it requires a little more work to set up.

Here’s a model with sample schema:

# models.py

from django.db import models
from django_jsonform.models.fields import JSONField


class ShoppingList(models.Model):
    ITEMS_SCHEMA = {
        'type': 'array', # a list which will contain the items
        'items': {
            'type': 'string' # items in the array are strings
        }
    }

    items = JSONField(schema=ITEMS_SCHEMA)
    date_created = models.DateTimeField(auto_now_add=True)

Admin

Register your model for the admin site:

# admin.py

from django.contrib import admin
from myapp.models import ShoppingList


admin.site.register(ShoppingList)

Now go to the admin site and visit the “Add new” shopping list page. The form should look something like this:

Animated screenshot of admin page

Next steps

  • The User’s guide contains further details about various input types, uploading files and other features.

  • See Schema guide for a reference on the supported schema.

  • See Fields and Widgets for available fields and widgets.

  • See Examples for sample schemas for declaring complex data structures.