A simple Django app to add JSON widget into Django Administration.
Project description
Django Administration JSON Editor
Application adds support for editing JSONField in Django Administration via https://github.com/json-editor/json-editor.
Quick start
Install application via pip:
pip install django-admin-json-editor
Add application to the INSTALLED_APPS settings:
INSTALLED_APPS = [
...
'django_admin_json_editor',
...
]
Define schema of json field:
DATA_SCHEMA = {
'type': 'object',
'title': 'Data',
'properties': {
'text': {
'title': 'Some text',
'type': 'string',
'format': 'textarea',
},
'status': {
'title': 'Status',
'type': 'boolean',
},
},
}
Use JSONEditorWidget to bind editor to the form field:
class JSONModelAdminForm(forms.ModelForm):
class Meta:
model = JSONModel
fields = '__all__'
widgets = {
'data': JSONEditorWidget(DATA_SCHEMA, collapsed=False),
}
Dynamic schema
It is possible to build dynamic schema for widget:
def dynamic_schema(widget):
return {
'type': 'array',
'title': 'tags',
'items': {
'type': 'string',
'enum': [i for i in Tag.objects.values_list('name', flat=True)],
}
}
@admin.register(JSONModel)
class JSONModelAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
widget = JSONEditorWidget(dynamic_schema, False)
form = super().get_form(request, obj, widgets={'tags': widget}, **kwargs)
return form
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
django-admin-json-editor-0.2.2.tar.gz
(954.8 kB
view hashes)
Close
Hashes for django-admin-json-editor-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0548152f13c7d12b28918a1dad051e75a09b696e05dbf98231d28eb75f2576c4 |
|
MD5 | c5265800ec1e3bc1829ab67b5082caf4 |
|
BLAKE2b-256 | 21a78342fc9987224019740e61a2f014c1c7447e7fa7012fcbfeeaebc688863e |