django-jsonform

2.23.2 · active · verified Wed Apr 15

django-jsonform is a Django library that provides a user-friendly form interface for editing JSON data directly within the Django admin. It leverages JSON schema to define the structure of the JSON data, automatically generating dynamic forms for creating and editing. The library also supports PostgreSQL's ArrayField with multiple levels of nesting. As of version 2.23.2, it maintains an active development pace with several releases per year, addressing bugs and introducing new features.

Warnings

Install

Imports

Quickstart

To quickly integrate `django-jsonform`, define a `JSONField` in your Django model with a corresponding JSON schema. Then, register your model with the Django admin. The library will automatically render a dynamic form based on your schema. Remember to add `django_jsonform` to your `INSTALLED_APPS` and run `collectstatic` for the JavaScript assets to load correctly.

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

# models.py
class ShoppingList(models.Model):
    name = models.CharField(max_length=255)
    items = JSONField(
        schema={
            'type': 'array',
            'title': 'Shopping Items',
            'items': {
                'type': 'dict',
                'keys': {
                    'item_name': {'type': 'string', 'title': 'Item Name'},
                    'quantity': {'type': 'integer', 'title': 'Quantity', 'minimum': 1}
                }
            }
        },
        help_text='A list of items for shopping.'
    )

    def __str__(self):
        return self.name

# admin.py
# Ensure 'django_jsonform' is in INSTALLED_APPS in settings.py
@admin.register(ShoppingList)
class ShoppingListAdmin(admin.ModelAdmin):
    list_display = ('name',)

# To see the form in action:
# 1. Add 'django_jsonform' to INSTALLED_APPS in your settings.py
# 2. Run 'python manage.py makemigrations' and 'python manage.py migrate'
# 3. Run 'python manage.py createsuperuser' and log in to the Django admin.

view raw JSON →