Metadata-Version: 2.0
Name: django-jsoneditor
Version: 0.0.9
Summary: Django JSON Editor
Home-page: https://github.com/nnseva/django-jsoneditor
Author: Vsevolod Novikov
Author-email: nnseva@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Requires-Dist: packaging

Django-JSONEditor
===================

Django-JSONEditor is an online structured JSON input widget for Django appropriate for various JSONField's provided for Django.

Code of the javascript JSONEditor online editor has been got from the http://jsoneditoronline.org/.

See the latest versions of the javascript online JSON Editor here: https://github.com/josdejong/jsoneditor

Sample views:

.. image:: https://raw.github.com/josdejong/jsoneditor/master/misc/jsoneditor.png

*Don't mismatch this repo with* https://github.com/skyhood/django-jsoneditor

Installation
------------
Latest version from the GIT repository::

    pip install "git+git://github.com/nnseva/django-jsoneditor.git"

Stable version from the PyPi repository::

    pip install django-jsoneditor


Note that you should use one of original JSONField packages to provide the JSONField itself.

Configuration
-------------

You **should** append ``jsoneditor`` into the ``INSTALLED_APPS`` of your ``settings.py`` file:

.. code:: python

    INSTALLED_APPS = (
        ...
        'jsoneditor',
        ...
    )

You **can** use CDN repositories to get JSONEditor javascript code, or host it yourself, instead of the packaged one using the following two settings in your ``settings.py`` file:

.. code:: python

    JSON_EDITOR_JS = 'whatever-your-want.js'
    JSON_EDITOR_CSS = 'whatever-your-want.css'

Just look to the http://cdnjs.com/libraries/jsoneditor and select the latest one, like:

.. code:: python

    JSON_EDITOR_JS = 'https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/4.2.1/jsoneditor.js'
    JSON_EDITOR_CSS = 'https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/4.2.1/jsoneditor.css'

Use
----

You can use the JSONEditor widget for fields in selected Admin classes like

admin.py

.. code:: python

    from json_field import JSONField
    from jsoneditor.forms import JSONEditor
    class MyAdmin(admin.ModelAdmin):
        formfield_overrides = {
            JSONField:{ 'widget':JSONEditor },
        }

Or use the original JSONField implementation fixed by the package.

Right now there are three fixed implementations:

* ``jsoneditor.fields.django_json_field.JSONField`` replaces a ``JSONField`` from https://github.com/derek-schaefer/django-json-field (**NOTE** the package is not compatible with django v.1.9)
* ``jsoneditor.fields.django_jsonfield.JSONField`` replaces a ``JSONField`` from https://github.com/bradjasper/django-jsonfield
* ``jsoneditor.fields.postgres_jsonfield.JSONField`` replaces ``django.contrib.postgres.fields.JSONField`` (**NOTE** this field type appears only from django v.1.9)

Use the fixed implementation instead of the original one.

models.py

.. code:: python

    from django.db import models

    # from json_field import JSONField replaced by:
    from jsoneditor.fields.django_json_field import JSONField
    # Create your models here.

    class TestModel(models.Model):
        my_field = JSONField()

You can access the underlying ``JSONEditor`` JS objects in your JavaScript via dictionary named ``jsonEditors``. This dictionary's keys are the IDs of the fields generated by this component in the form: ``"id"+[your form field name]+"_json_jsoneditor"``, e.g. ``id_template_parameters_json_jsoneditor``. The values in the dictionary are the instances of the correspondent JSONEditor objects.


