JSONEditor-based widget for Django admin JSONField with tree/code/view modes.
Project description
django-jsonfield-formatter
Installable Django app that replaces the default admin widget for JSONField with JSONEditor (tree, code, and view modes, search, navigation bar, and prettified editing).
Requirements
- Python 3.10+
- Django 4.2+
Install
pip install django-jsonfield-formatter
Or from a checkout:
pip install -e .
Setup
- Add the app to
INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"jsonfield_formatter",
]
- Run
collectstaticin production sojsoneditor.min.js,jsoneditor.min.css, and icons are available.
Usage in the admin
Option A — formfield_overrides
from django.contrib import admin
from django.db.models import JSONField
from jsonfield_formatter.widgets import JSONFormatterWidget
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {"widget": JSONFormatterWidget},
}
Option B — mixin
from django.contrib import admin
from jsonfield_formatter.admin import JSONFormatterAdminMixin
@admin.register(MyModel)
class MyModelAdmin(JSONFormatterAdminMixin, admin.ModelAdmin):
pass
If you already use formfield_overrides, merge JSONField into your dict instead of using the mixin.
Widget options
JSONFormatterWidget accepts:
| Argument | Description |
|---|---|
attrs |
Extra HTML attributes for the textarea (e.g. class). |
mode |
Initial mode: tree, code, or view (default tree). |
height |
CSS height for the editor area (default 400px). |
editor_options |
Dict merged into JSONEditor’s options (see JSONEditor API). |
Example:
JSONFormatterWidget(
mode="code",
height="min(60vh, 520px)",
editor_options={"sortObjectKeys": True},
)
Bundled JSONEditor version
Static files are vendored from jsoneditor 10.1.0 (see jsonfield_formatter/widgets.py).
Development
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_jsonfield_formatter-0.1.0.tar.gz.
File metadata
- Download URL: django_jsonfield_formatter-0.1.0.tar.gz
- Upload date:
- Size: 290.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2a2a2b537353e3207a3b96755363f2c1c327e1bbe5eb7be202ee3cc4f44636a
|
|
| MD5 |
dae89e64fee90d856d346900e2e98d5c
|
|
| BLAKE2b-256 |
381b279b53493df9fb5ef3aa8940f9b4e32731dd456901ab9ec1fdbb02cde077
|
File details
Details for the file django_jsonfield_formatter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_jsonfield_formatter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 292.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f16cd80f87874d3d506987ac86b12158e9dd3359ba1cf44931cc55be6d6205f4
|
|
| MD5 |
0e96d95d823ae00506a5bed4c8880d19
|
|
| BLAKE2b-256 |
b8ff4a5a8db5b995ada0fb9c109f6c9f4b7f5406d08e8d65ffa2ddb8e7b8a83a
|