bpartridge / django-json-widget

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

django-json-widget

https://travis-ci.org/jmrivas86/django-json-widget.svg?branch=master

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)

Quickstart

Install django-json-widget:

pip install django-json-widget

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_json_widget',
    ...
)

Add the widget in your admin.py:

from django.contrib import admin
from django.contrib.postgres import fields
from django_json_widget.widgets import JSONEditorWidget
from .models import YourModel


@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        fields.JSONField: {'widget': JSONEditorWidget},
    }

You can also add the widget in your forms.py and choose the default mode:

from django import forms
from django_json_widget.widgets import JSONEditorWidget
from .models import YourModel


class YourForm(forms.ModelForm):
    class Meta:
        model = YourModel

        fields = ('jsonfield',)

        widgets = {
            # choose one mode from ['text', 'code', 'tree', 'form', 'view']
            'jsonfield': JSONEditorWidget(mode='code')
        }

JSONEditorWidget widget

Before:

https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_0.png

After:

https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_1.png

Credits

Tools used in rendering this package:

About

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)

License:MIT License


Languages

Language:Python 70.2%Language:HTML 20.7%Language:Makefile 9.1%