Skip to main content

Django json widget is an alternative widget that makes it easy to edit the jsonfield field of django.

Project description

https://badge.fury.io/py/django-json-widget.svg https://travis-ci.org/jmrivas86/django-json-widget.svg?branch=master https://codecov.io/gh/jmrivas86/django-json-widget/branch/master/graph/badge.svg

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:

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 = {
            'jsonfield': JSONEditorWidget
        }

Configuration

You can customize the JSONEditorWidget with the following options:

  • width: Width of the editor as a string with CSS size units (px, em, % etc). Defaults to 90%.

  • height: Height of the editor as a string CSS size units. Defaults to 550px.

  • options: A dict of options accepted by the JSON editor. Options that require functions (eg. onError) are not supported.

  • mode (deprecated): The default editor mode. This argument is redundant because it can be specified as a part of options. Preserved for backwards compatibility with version 0.2.0.

  • attrs: HTML attributes to be applied to the wrapper element. See the Django Widget documentation.

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:

History

0.1.0 (2017-05-10)

  • First release on PyPI.

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-json-widget-1.0.1.tar.gz (192.4 kB view details)

Uploaded Source

File details

Details for the file django-json-widget-1.0.1.tar.gz.

File metadata

  • Download URL: django-json-widget-1.0.1.tar.gz
  • Upload date:
  • Size: 192.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.5

File hashes

Hashes for django-json-widget-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c582cf6284598ec2e601ac3b326784d59fa1be8df2967d27c74083e66bc75d4a
MD5 75337414133d51d3b8340363c11a1e8a
BLAKE2b-256 e79a37a878cb00a7b55385bb0c244d01416d511af95353ea936b84d2e4ebbda1

See more details on using hashes here.

Supported by

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