Skip to main content

A simple Django app to add JSON widget into Django Administration.

Project description

Django Administration JSON Editor

Build Status

Admin Json Editor

Application adds support for editing JSONField in Django Administration via https://github.com/json-editor/json-editor.

Quick start

Install application via pip:

pip install django-admin-json-editor

Add application to the INSTALLED_APPS settings:

INSTALLED_APPS = [
    ...
    'django_admin_json_editor',
    ...
]

Define schema of json field:

DATA_SCHEMA = {
    'type': 'object',
    'title': 'Data',
    'properties': {
        'text': {
            'title': 'Some text',
            'type': 'string',
            'format': 'textarea',
        },
        'status': {
            'title': 'Status',
            'type': 'boolean',
        },
    },
}

Use JSONEditorWidget to bind editor to the form field:

class JSONModelAdminForm(forms.ModelForm):
    class Meta:
        model = JSONModel
        fields = '__all__'
        widgets = {
            'data': JSONEditorWidget(DATA_SCHEMA, collapsed=False),
        }

Dynamic schema

It is possible to build dynamic schema for widget:

def dynamic_schema(widget):
    return {
        'type': 'array',
        'title': 'tags',
        'items': {
            'type': 'string',
            'enum': [i for i in Tag.objects.values_list('name', flat=True)],
        }
    }
@admin.register(JSONModel)
class JSONModelAdmin(admin.ModelAdmin):
    def get_form(self, request, obj=None, **kwargs):
        widget = JSONEditorWidget(dynamic_schema, False)
        form = super().get_form(request, obj, widgets={'tags': widget}, **kwargs)
        return form

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-admin-json-editor-0.2.3.tar.gz (843.4 kB view details)

Uploaded Source

File details

Details for the file django-admin-json-editor-0.2.3.tar.gz.

File metadata

  • Download URL: django-admin-json-editor-0.2.3.tar.gz
  • Upload date:
  • Size: 843.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7

File hashes

Hashes for django-admin-json-editor-0.2.3.tar.gz
Algorithm Hash digest
SHA256 12cf9dd1288f83f5ec83fbe2a39668e79a85e33bfbeb08157a6f5c7c4e480e20
MD5 990bca6805988987f33a504ee9facb2e
BLAKE2b-256 dbeb33401a7c47b078b12a281952c6e963906602a3eeff13f400adda15e4de7f

See more details on using hashes here.

Supported by

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