Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmrivas86/django-json-widget
An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
https://github.com/jmrivas86/django-json-widget
Last synced: 5 days ago
JSON representation
An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
- Host: GitHub
- URL: https://github.com/jmrivas86/django-json-widget
- Owner: jmrivas86
- License: mit
- Created: 2017-05-14T19:01:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T11:56:55.000Z (7 months ago)
- Last Synced: 2024-09-18T17:13:09.747Z (about 2 months ago)
- Language: Python
- Size: 747 KB
- Stars: 432
- Watchers: 7
- Forks: 88
- Open Issues: 20
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Authors: AUTHORS.rst
Awesome Lists containing this project
- awesome-django-admin - django-json-widget - An alternative widget that makes it easy to edit the Django's JSONField (Packages to install at your project / Widgets / Fields)
- awesome-hacking-lists - jmrivas86/django-json-widget - An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields) (Python)
README
=============================
django-json-widget
=============================.. image:: https://badge.fury.io/py/django-json-widget.svg
:target: https://badge.fury.io/py/django-json-widget.. image:: https://travis-ci.org/jmrivas86/django-json-widget.svg?branch=master
:target: https://travis-ci.org/jmrivas86/django-json-widget.. image:: https://codecov.io/gh/jmrivas86/django-json-widget/branch/master/graph/badge.svg
:target: https://codecov.io/gh/jmrivas86/django-json-widgetAn 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`:
.. code-block:: python
INSTALLED_APPS = (
...
'django_json_widget',
...
)Add the widget in your admin.py:
.. code-block:: python
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:
.. code-block:: python
from django import forms
from django_json_widget.widgets import JSONEditorWidget
from .models import YourModelclass YourForm(forms.ModelForm):
class Meta:
model = YourModelfields = ('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`_... _json editor: https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#configuration-options
.. _Django Widget documentation: https://docs.djangoproject.com/en/2.1/ref/forms/widgets/#django.forms.Widget.attrsJSONEditorWidget widget
-----------------------Before:
.. image:: https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_0.png
After:
.. image:: https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_1.png
Credits
-------Tools used in rendering this package:
* Cookiecutter_
* `cookiecutter-djangopackage`_.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage