Django json widget is an alternative widget that makes it easy to edit the jsonfield field of django.
Project description
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.db.models import JSONField
from django_json_widget.widgets import JSONEditorWidget
from .models import YourModel
@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
formfield_overrides = {
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:
After:
Credits
Tools used in rendering this package:
History
0.1.0 (2017-05-10)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-json-widget-2.0.1.tar.gz
.
File metadata
- Download URL: django-json-widget-2.0.1.tar.gz
- Upload date:
- Size: 292.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adb4cab17fe5a04139037d7d84725369530ef35b912c3790d3a7b13f99351358 |
|
MD5 | cc864bac07dfc9eb780e0555574968e8 |
|
BLAKE2b-256 | 5909e3f70ed588e634d9de5d059347ff3445419fff42b7bff44241500aef2216 |