Skip to main content

JSON input widget for paper-admin

Project description

paper-jsoneditor

JSON input widget for paper-admin.

PyPI Build Status Software license

Compatibility

  • python >= 3.6
  • django >= 3.1
  • paper-admin >= 4.1.0

Installation

Install the latest release with pip:

pip install paper-jsoneditor

Add paper_jsoneditor to your INSTALLED_APPS in django's settings.py:

INSTALLED_APPS = (
    # other apps
    "paper_jsoneditor",
)

Usage

from django.db import models
from django.utils.translation import gettext_lazy as _
from paper_jsoneditor.fields import JSONField


class SampleModel(models.Model):
    data = JSONField(
        _("JSON"),
        blank=True
    )

    class Meta:
        verbose_name = _("Sample")

Result: image

Preserving JSON object keys order

By default, Django uses the jsonb internal type for JSONField (for PostgreSQL).

From the Postgres documentation:

<...> jsonb does not preserve white space, does not preserve the order of object keys, and does not keep duplicate object keys. If duplicate keys are specified in the input, only the last value is kept.

In general, most applications should prefer to store JSON data as jsonb, unless there are quite specialized needs, such as legacy assumptions about ordering of object keys.

If you really do need to preserve the key order, use OrderedJSONField. It uses the TEXT type to store data:

from django.db import models
from django.utils.translation import gettext_lazy as _
from paper_jsoneditor.fields import OrderedJSONField


class SampleModel(models.Model):
    data = OrderedJSONField(
        _("JSON"),
        blank=True
    )

    class Meta:
        verbose_name = _("Sample")

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

paper-jsoneditor-0.0.2.tar.gz (857.2 kB view hashes)

Uploaded Source

Built Distribution

paper_jsoneditor-0.0.2-py2.py3-none-any.whl (863.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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