django-json-widget 2.1.0__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. django_json_widget-2.2.0/.github/workflows/javascript-tests.yml +18 -0
  2. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/.github/workflows/tests.yml +1 -1
  3. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/.gitignore +4 -0
  4. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/CHANGELOG.rst +12 -0
  5. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/CONTRIBUTING.md +3 -3
  6. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/PKG-INFO +301 -237
  7. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/README.rst +57 -0
  8. django_json_widget-2.2.0/django_json_widget/__init__.py +1 -0
  9. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/static/dist/jsoneditor.min.css +2 -2
  10. django_json_widget-2.2.0/django_json_widget/static/django_json_widget.js +38 -0
  11. django_json_widget-2.2.0/django_json_widget/templates/django_json_widget.html +7 -0
  12. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/widgets.py +8 -0
  13. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget.egg-info/PKG-INFO +301 -237
  14. django_json_widget-2.2.0/django_json_widget.egg-info/SOURCES.txt +99 -0
  15. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget.egg-info/not-zip-safe +1 -1
  16. django_json_widget-2.2.0/example/characters/admin.py +20 -0
  17. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/characters/models.py +5 -0
  18. django_json_widget-2.2.0/example/example/reproduction_settings.py +3 -0
  19. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/example/settings.py +3 -7
  20. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/manage.py +0 -0
  21. django_json_widget-2.2.0/example/wagtail_demo/.dockerignore +39 -0
  22. django_json_widget-2.2.0/example/wagtail_demo/DEMO.md +21 -0
  23. django_json_widget-2.2.0/example/wagtail_demo/Dockerfile +60 -0
  24. django_json_widget-2.2.0/example/wagtail_demo/home/apps.py +6 -0
  25. django_json_widget-2.2.0/example/wagtail_demo/home/migrations/0001_initial.py +31 -0
  26. django_json_widget-2.2.0/example/wagtail_demo/home/migrations/0002_create_homepage.py +66 -0
  27. django_json_widget-2.2.0/example/wagtail_demo/home/migrations/0003_homepage_settings_json_jsonitem.py +28 -0
  28. django_json_widget-2.2.0/example/wagtail_demo/home/migrations/__init__.py +0 -0
  29. django_json_widget-2.2.0/example/wagtail_demo/home/models.py +23 -0
  30. django_json_widget-2.2.0/example/wagtail_demo/home/static/css/welcome_page.css +184 -0
  31. django_json_widget-2.2.0/example/wagtail_demo/home/templates/home/home_page.html +21 -0
  32. django_json_widget-2.2.0/example/wagtail_demo/home/templates/home/welcome_page.html +52 -0
  33. django_json_widget-2.2.0/example/wagtail_demo/home/tests.py +42 -0
  34. django_json_widget-2.2.0/example/wagtail_demo/manage.py +22 -0
  35. django_json_widget-2.2.0/example/wagtail_demo/requirements.txt +2 -0
  36. django_json_widget-2.2.0/example/wagtail_demo/search/__init__.py +0 -0
  37. django_json_widget-2.2.0/example/wagtail_demo/search/templates/search/search.html +38 -0
  38. django_json_widget-2.2.0/example/wagtail_demo/search/views.py +46 -0
  39. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/__init__.py +0 -0
  40. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/settings/__init__.py +0 -0
  41. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/settings/base.py +182 -0
  42. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/settings/dev.py +18 -0
  43. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/settings/production.py +14 -0
  44. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/static/css/wagtail_demo.css +0 -0
  45. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/static/js/wagtail_demo.js +0 -0
  46. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/templates/404.html +11 -0
  47. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/templates/500.html +13 -0
  48. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/templates/base.html +46 -0
  49. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/urls.py +35 -0
  50. django_json_widget-2.2.0/example/wagtail_demo/wagtail_demo/wsgi.py +16 -0
  51. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/requirements_dev.txt +8 -9
  52. django_json_widget-2.2.0/requirements_test.txt +2 -0
  53. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/setup.cfg +16 -16
  54. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/setup.py +1 -6
  55. django_json_widget-2.2.0/tests/__init__.py +0 -0
  56. django_json_widget-2.2.0/tests/test_inline_editor.js +76 -0
  57. django_json_widget-2.2.0/tests/test_jsoneditor_access.py +47 -0
  58. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/tests/test_logic.py +14 -11
  59. django_json_widget-2.2.0/tests/test_wagtail.py +73 -0
  60. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/tests/test_widget_security.py +2 -2
  61. django_json_widget-2.2.0/tests/wagtail_settings.py +19 -0
  62. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/tox.ini +4 -9
  63. django_json_widget-2.1.0/django_json_widget/__init__.py +0 -1
  64. django_json_widget-2.1.0/django_json_widget/templates/django_json_widget.html +0 -29
  65. django_json_widget-2.1.0/django_json_widget.egg-info/SOURCES.txt +0 -62
  66. django_json_widget-2.1.0/example/characters/admin.py +0 -11
  67. django_json_widget-2.1.0/requirements_test.txt +0 -7
  68. django_json_widget-2.1.0/tests/test_jsoneditor_access.py +0 -60
  69. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/.coveragerc +0 -0
  70. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/.editorconfig +0 -0
  71. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/.github/ISSUE_TEMPLATE.md +0 -0
  72. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/.travis.yml +0 -0
  73. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/AUTHORS.rst +0 -0
  74. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/LICENSE +0 -0
  75. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/MANIFEST.in +0 -0
  76. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/Makefile +0 -0
  77. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/apps.py +0 -0
  78. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/models.py +0 -0
  79. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/static/css/django_json_widget.css +0 -0
  80. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/static/dist/img/jsoneditor-icons.svg +0 -0
  81. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/static/dist/jsoneditor.min.js +0 -0
  82. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/urls.py +0 -0
  83. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget/views.py +0 -0
  84. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget.egg-info/dependency_links.txt +0 -0
  85. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/django_json_widget.egg-info/top_level.txt +0 -0
  86. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/README.md +0 -0
  87. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/characters/__init__.py +0 -0
  88. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/characters/apps.py +0 -0
  89. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/characters/migrations/0001_initial.py +0 -0
  90. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/characters/migrations/0002_alter_character_data_alter_character_other_data.py +0 -0
  91. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/characters/migrations/__init__.py +0 -0
  92. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/characters/tests.py +0 -0
  93. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/characters/views.py +0 -0
  94. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/example/__init__.py +0 -0
  95. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/example/urls.py +0 -0
  96. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/example/wsgi.py +0 -0
  97. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/requirements.txt +0 -0
  98. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/example/templates/django_json_widget/base.html +0 -0
  99. {django_json_widget-2.1.0/tests → django_json_widget-2.2.0/example/wagtail_demo/home}/__init__.py +0 -0
  100. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/imgs/jsonfield_0.png +0 -0
  101. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/imgs/jsonfield_1.png +0 -0
  102. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/manage.py +0 -0
  103. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/pyproject.toml +0 -0
  104. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/requirements.txt +0 -0
  105. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/tests/settings.py +0 -0
  106. {django_json_widget-2.1.0 → django_json_widget-2.2.0}/tests/templates/django/forms/widgets/attrs.html +0 -0
@@ -0,0 +1,18 @@
1
+ name: JavaScript Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ inline-editor:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-node@v4
15
+ with:
16
+ node-version: '20'
17
+ - name: Test inline editor initialization
18
+ run: node --test tests/test_inline_editor.js
@@ -13,7 +13,7 @@ jobs:
13
13
  strategy:
14
14
  max-parallel: 5
15
15
  matrix:
16
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
16
+ python-version: ['3.11', '3.12', '3.13']
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v4
@@ -55,3 +55,7 @@ docs/_build
55
55
  # OS
56
56
  .DS_Store
57
57
  example/.DS_Store
58
+
59
+ # Local SQLite databases
60
+ *.sqlite3
61
+ *.sqlite3-*
@@ -2,6 +2,18 @@
2
2
  Changelog
3
3
  =========
4
4
 
5
+ 2.2.0 (2026-11-13)
6
+ ------------------
7
+
8
+ * Added CSP guide.
9
+ * Implemented Wagtail support.
10
+ * Fixed inline editors.
11
+
12
+ 2.1.1 (2025-12-12)
13
+ ------------------
14
+
15
+ * Issue #108: respect Django admin color scheme setting for JSON editor.
16
+
5
17
  2.1.0 (2025-10-24)
6
18
  ------------------
7
19
 
@@ -57,9 +57,9 @@ Ready to contribute? Here's how to set up `django-json-widget` for local develop
57
57
  pip install -r requirements_test.txt
58
58
  ```
59
59
 
60
- 4. Create a branch for local development from the dev branch:
60
+ 4. Create a branch for local development from the master branch:
61
61
  ```bash
62
- git checkout dev
62
+ git checkout master
63
63
  git checkout -b name-of-your-branch
64
64
  ```
65
65
 
@@ -78,6 +78,6 @@ Ready to contribute? Here's how to set up `django-json-widget` for local develop
78
78
 
79
79
  Before you submit a pull request, check that it meets these guidelines:
80
80
 
81
- 1. **The pull request must be submitted against the `dev` branch.**
81
+ 1. **The pull request must be submitted against the `master` branch.**
82
82
  2. Please explain what you have done in the pull request.
83
83
  3. Make sure you have had passed pre-commit hooks.
@@ -1,237 +1,301 @@
1
- Metadata-Version: 2.4
2
- Name: django-json-widget
3
- Version: 2.1.0
4
- Summary: Django json widget is an alternative widget that makes it easy to edit the jsonfield field of django.
5
- Home-page: https://github.com/jmrivas86/django-json-widget
6
- Author: José Manuel Rivas
7
- Author-email: jmrivas86@gmail.com
8
- License: MIT
9
- Keywords: django-json-widget
10
- Classifier: Development Status :: 5 - Production/Stable
11
- Classifier: Framework :: Django
12
- Classifier: Framework :: Django :: 3.2
13
- Classifier: Framework :: Django :: 4.2
14
- Classifier: Framework :: Django :: 5.0
15
- Classifier: Framework :: Django :: 5.2
16
- Classifier: Intended Audience :: Developers
17
- Classifier: License :: OSI Approved :: BSD License
18
- Classifier: Natural Language :: English
19
- Classifier: Programming Language :: Python :: 3
20
- Classifier: Programming Language :: Python :: 3.9
21
- Classifier: Programming Language :: Python :: 3.10
22
- Classifier: Programming Language :: Python :: 3.11
23
- Classifier: Programming Language :: Python :: 3.12
24
- Classifier: Programming Language :: Python :: 3.13
25
- License-File: LICENSE
26
- License-File: AUTHORS.rst
27
- Dynamic: author
28
- Dynamic: author-email
29
- Dynamic: classifier
30
- Dynamic: description
31
- Dynamic: home-page
32
- Dynamic: keywords
33
- Dynamic: license
34
- Dynamic: license-file
35
- Dynamic: summary
36
-
37
- =============================
38
- django-json-widget
39
- =============================
40
-
41
- .. image:: https://badge.fury.io/py/django-json-widget.svg
42
- :target: https://badge.fury.io/py/django-json-widget
43
-
44
-
45
- An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
46
-
47
-
48
- Quickstart
49
- ----------
50
-
51
- Install django-json-widget::
52
-
53
- pip install django-json-widget
54
-
55
- Add it to your `INSTALLED_APPS`:
56
-
57
- .. code-block:: python
58
-
59
- INSTALLED_APPS = (
60
- ...
61
- 'django_json_widget',
62
- ...
63
- )
64
-
65
- Add the widget in your admin.py:
66
-
67
- .. code-block:: python
68
-
69
- from django.contrib import admin
70
- from django.db.models import JSONField
71
- from django_json_widget.widgets import JSONEditorWidget
72
- from .models import YourModel
73
-
74
-
75
- @admin.register(YourModel)
76
- class YourModelAdmin(admin.ModelAdmin):
77
- formfield_overrides = {
78
- JSONField: {'widget': JSONEditorWidget},
79
- }
80
-
81
- You can also add the widget in your forms.py:
82
-
83
- .. code-block:: python
84
-
85
- from django import forms
86
- from django_json_widget.widgets import JSONEditorWidget
87
- from .models import YourModel
88
-
89
-
90
- class YourForm(forms.ModelForm):
91
- class Meta:
92
- model = YourModel
93
-
94
- fields = ('jsonfield',)
95
-
96
- widgets = {
97
- 'jsonfield': JSONEditorWidget
98
- }
99
-
100
- Configuration
101
- -------------
102
-
103
- You can customize the JSONEditorWidget with the following options:
104
-
105
- * **width**: Width of the editor as a string with CSS size units (px, em, % etc). Defaults to ``90%``.
106
- * **height**: Height of the editor as a string CSS size units. Defaults to ``550px``.
107
- * **options**: A dict of options accepted by the `JSON editor`_. Options that require functions (eg. onError) are not supported.
108
- * **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.
109
- * **attrs**: HTML attributes to be applied to the wrapper element. See the `Django Widget documentation`_.
110
-
111
- Accessing JsonEditor Instance
112
- -----------------------------
113
-
114
- The JsonEditor instance is automatically exposed for external access through two methods:
115
-
116
- 1. **Window object**: Available as ``window['FIELD_ID_editor']`` where FIELD_ID is the field's HTML ID
117
- 2. **DOM element**: Available as ``container.jsonEditor`` property on the widget's container element
118
-
119
- Example usage for external JavaScript access:
120
-
121
- .. code-block:: javascript
122
-
123
- // Access via window object
124
- var editor = window['id_jsonfield_editor'];
125
- editor.set({'key': 'new value'});
126
-
127
- // Access via DOM element
128
- var container = document.getElementById('id_jsonfield');
129
- var editor = container.jsonEditor;
130
- editor.set({'key': 'new value'});
131
-
132
- This allows you to programmatically call JsonEditor methods like ``set()``, ``get()``, ``update()``, etc. from custom JavaScript code running in your admin pages or forms.
133
-
134
- .. _json editor: https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#configuration-options
135
- .. _Django Widget documentation: https://docs.djangoproject.com/en/2.1/ref/forms/widgets/#django.forms.Widget.attrs
136
-
137
-
138
- JSONEditorWidget widget
139
- -----------------------
140
-
141
- Before:
142
-
143
- .. image:: https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_0.png
144
-
145
- After:
146
-
147
- .. image:: https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_1.png
148
-
149
-
150
- Development Guide
151
- -----------------
152
-
153
- Read the contribution guide.
154
-
155
-
156
- Credits
157
- -------
158
-
159
- Tools used in rendering this package:
160
-
161
- * Cookiecutter_
162
- * `cookiecutter-djangopackage`_
163
-
164
- .. _Cookiecutter: https://github.com/audreyr/cookiecutter
165
- .. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage
166
-
167
-
168
- =========
169
- Changelog
170
- =========
171
-
172
- 2.1.0 (2025-10-24)
173
- ------------------
174
-
175
- * Issue #114: expose editor instance to window object and DOM element.
176
-
177
- 2.0.4 (2025-10-11)
178
- ------------------
179
-
180
- * Fix dark mode CSS support #107
181
-
182
- 2.0.3 (2025-07-29)
183
- ------------------
184
-
185
- 2.0.2 (2025-07-28)
186
- ------------------
187
-
188
- * Fix Version 2.0.1 causes rendering HTML scripts issue #80
189
-
190
- 2.0.1 (2024-03-02)
191
- ------------------=
192
-
193
- * Fixed Version 2.0.0 causes issues with Django 4.x due to missing sourcemaps issue #83
194
-
195
- 2.0.0 (2024-03-24)
196
- ------------------
197
-
198
- * Fix default paths for static files #53
199
- * Stop declaring support for Django versions before 3.2 #65
200
- * Avoid HTML injection via unsafe JSON injection #64
201
- * Remove source map reference from JS bundle #70
202
- * Add dark mode CSS support #82
203
- * Updated documentation
204
-
205
- 1.1.1 (2021-02-17)
206
- ------------------
207
-
208
- * Fix for issue #51, updates the bundled libs to 9.1.9 and additional notes for Django 3.1 changes
209
-
210
- 1.1.0 (2021-02-05)
211
- ------------------
212
-
213
- * Added functionality to override version of JSONEditor to use
214
- * update readme for django 3.1
215
-
216
- 1.0.1 (2020-04-17)
217
- ------------------
218
-
219
- * Stop resolving paths to the static files
220
-
221
- 1.0.0 (2020-01-16)
222
- ------------------
223
-
224
- * Update Makefile
225
- * Make Stable the project
226
-
227
-
228
- 0.3.0 (2020-01-16)
229
- ------------------
230
-
231
- * Update requirements.txt
232
- * Fixed static to work with CDN tools like django-storages
233
- * Make widget more configurable
234
- * Fixed an incompatibility with Python 2.7
235
- * update jsoneditor to latest version
236
-
237
-
1
+ Metadata-Version: 2.4
2
+ Name: django-json-widget
3
+ Version: 2.2.0
4
+ Summary: Django json widget is an alternative widget that makes it easy to edit the jsonfield field of django.
5
+ Home-page: https://github.com/jmrivas86/django-json-widget
6
+ Author: José Manuel Rivas
7
+ Author-email: jmrivas86@gmail.com
8
+ License: MIT
9
+ Keywords: django-json-widget
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Framework :: Django
12
+ Classifier: Framework :: Django :: 5.0
13
+ Classifier: Framework :: Django :: 5.2
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: BSD License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ License-File: LICENSE
21
+ License-File: AUTHORS.rst
22
+ Dynamic: author
23
+ Dynamic: author-email
24
+ Dynamic: classifier
25
+ Dynamic: description
26
+ Dynamic: home-page
27
+ Dynamic: keywords
28
+ Dynamic: license
29
+ Dynamic: license-file
30
+ Dynamic: summary
31
+
32
+ =============================
33
+ django-json-widget
34
+ =============================
35
+
36
+ .. image:: https://badge.fury.io/py/django-json-widget.svg
37
+ :target: https://badge.fury.io/py/django-json-widget
38
+
39
+
40
+ An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
41
+
42
+
43
+ Quickstart
44
+ ----------
45
+
46
+ Install django-json-widget::
47
+
48
+ pip install django-json-widget
49
+
50
+ Add it to your `INSTALLED_APPS`:
51
+
52
+ .. code-block:: python
53
+
54
+ INSTALLED_APPS = (
55
+ ...
56
+ 'django_json_widget',
57
+ ...
58
+ )
59
+
60
+ Add the widget in your admin.py:
61
+
62
+ .. code-block:: python
63
+
64
+ from django.contrib import admin
65
+ from django.db.models import JSONField
66
+ from django_json_widget.widgets import JSONEditorWidget
67
+ from .models import YourModel
68
+
69
+
70
+ @admin.register(YourModel)
71
+ class YourModelAdmin(admin.ModelAdmin):
72
+ formfield_overrides = {
73
+ JSONField: {'widget': JSONEditorWidget},
74
+ }
75
+
76
+ You can also add the widget in your forms.py:
77
+
78
+ .. code-block:: python
79
+
80
+ from django import forms
81
+ from django_json_widget.widgets import JSONEditorWidget
82
+ from .models import YourModel
83
+
84
+
85
+ class YourForm(forms.ModelForm):
86
+ class Meta:
87
+ model = YourModel
88
+
89
+ fields = ('jsonfield',)
90
+
91
+ widgets = {
92
+ 'jsonfield': JSONEditorWidget
93
+ }
94
+
95
+ Wagtail
96
+ -------
97
+
98
+ For a Django ``JSONField`` on a Wagtail page or snippet, pass the widget to
99
+ ``FieldPanel``. Add ``django_json_widget`` to ``INSTALLED_APPS`` as above.
100
+
101
+ .. code-block:: python
102
+
103
+ from django.db import models
104
+ from wagtail.admin.panels import FieldPanel
105
+ from wagtail.models import Page
106
+ from django_json_widget.widgets import JSONEditorWidget
107
+
108
+
109
+ class ConfigurationPage(Page):
110
+ configuration = models.JSONField(default=dict, blank=True)
111
+
112
+ content_panels = Page.content_panels + [
113
+ FieldPanel(
114
+ 'configuration',
115
+ widget=JSONEditorWidget(width='100%'),
116
+ ),
117
+ ]
118
+
119
+ Wagtail includes the widget's JavaScript and CSS through form media. The same
120
+ ``FieldPanel`` configuration can be used on a child model displayed through
121
+ ``InlinePanel``; editors initialize when rows are added. Django validates the
122
+ submitted JSON, including invalid or cleared input.
123
+
124
+ This integration is tested with Wagtail 7.2 and Django 5.2. It covers model
125
+ fields rendered by panels. Using the widget inside a custom ``StreamField``
126
+ block requires a Wagtail Telepath widget adapter.
127
+
128
+ Configuration
129
+ -------------
130
+
131
+ You can customize the JSONEditorWidget with the following options:
132
+
133
+ * **width**: Width of the editor as a string with CSS size units (px, em, % etc). Defaults to ``90%``.
134
+ * **height**: Height of the editor as a string CSS size units. Defaults to ``550px``.
135
+ * **options**: A dict of options accepted by the `JSON editor`_. Options that require functions (eg. onError) are not supported.
136
+ * **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.
137
+ * **attrs**: HTML attributes to be applied to the wrapper element. See the `Django Widget documentation`_.
138
+
139
+ Content Security Policy
140
+ -----------------------
141
+
142
+ The widget loads its executable initialization code from a static JavaScript
143
+ file. Its initial value is embedded in a non-executable ``application/json``
144
+ script element. However, the bundled JSONEditor and its Ace code editor are
145
+ not fully compatible with a strict Content Security Policy (CSP):
146
+
147
+ * The widget and editor use inline styles, and Ace injects style elements.
148
+ A policy that disallows inline styles can prevent the editor from displaying
149
+ correctly.
150
+ * The default ``code`` mode creates a ``blob:`` worker. A restrictive
151
+ ``worker-src`` can block it.
152
+ * JSON schema validation compiles schemas using JavaScript's ``Function``
153
+ constructor. A ``script-src`` that disallows ``'unsafe-eval'`` blocks this.
154
+
155
+ Consequently, allowing only ``'self'`` for scripts and styles is not sufficient
156
+ for all widget features. The CSP directives and relaxations needed depend on
157
+ the chosen editor modes and options; test the actual configuration with CSP
158
+ enforcement before deploying. Allowing inline styles, ``blob:`` workers, or
159
+ ``'unsafe-eval'`` weakens a policy, so projects that cannot accept those
160
+ exceptions should use a different editor or provide compatible assets via
161
+ ``JSON_EDITOR_JS`` and ``JSON_EDITOR_CSS``.
162
+
163
+ Accessing JsonEditor Instance
164
+ -----------------------------
165
+
166
+ The JsonEditor instance is automatically exposed for external access through two methods:
167
+
168
+ 1. **Window object**: Available as ``window['FIELD_ID_editor']`` where FIELD_ID is the field's HTML ID
169
+ 2. **DOM element**: Available as ``container.jsonEditor`` property on the widget's container element
170
+
171
+ Example usage for external JavaScript access:
172
+
173
+ .. code-block:: javascript
174
+
175
+ // Access via window object
176
+ var editor = window['id_jsonfield_editor'];
177
+ editor.set({'key': 'new value'});
178
+
179
+ // Access via DOM element
180
+ var container = document.getElementById('id_jsonfield');
181
+ var editor = container.jsonEditor;
182
+ editor.set({'key': 'new value'});
183
+
184
+ This allows you to programmatically call JsonEditor methods like ``set()``, ``get()``, ``update()``, etc. from custom JavaScript code running in your admin pages or forms.
185
+
186
+ .. _json editor: https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#configuration-options
187
+ .. _Django Widget documentation: https://docs.djangoproject.com/en/2.1/ref/forms/widgets/#django.forms.Widget.attrs
188
+
189
+
190
+ JSONEditorWidget widget
191
+ -----------------------
192
+
193
+ Before:
194
+
195
+ .. image:: https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_0.png
196
+
197
+ After:
198
+
199
+ .. image:: https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_1.png
200
+
201
+
202
+ Development Guide
203
+ -----------------
204
+
205
+ Read the contribution guide.
206
+
207
+
208
+ Credits
209
+ -------
210
+
211
+ Tools used in rendering this package:
212
+
213
+ * Cookiecutter_
214
+ * `cookiecutter-djangopackage`_
215
+
216
+ .. _Cookiecutter: https://github.com/audreyr/cookiecutter
217
+ .. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage
218
+
219
+
220
+ =========
221
+ Changelog
222
+ =========
223
+
224
+ 2.2.0 (2026-11-13)
225
+ ------------------
226
+
227
+ * Added CSP guide.
228
+ * Implemented Wagtail support.
229
+ * Fixed inline editors.
230
+
231
+ 2.1.1 (2025-12-12)
232
+ ------------------
233
+
234
+ * Issue #108: respect Django admin color scheme setting for JSON editor.
235
+
236
+ 2.1.0 (2025-10-24)
237
+ ------------------
238
+
239
+ * Issue #114: expose editor instance to window object and DOM element.
240
+
241
+ 2.0.4 (2025-10-11)
242
+ ------------------
243
+
244
+ * Fix dark mode CSS support #107
245
+
246
+ 2.0.3 (2025-07-29)
247
+ ------------------
248
+
249
+ 2.0.2 (2025-07-28)
250
+ ------------------
251
+
252
+ * Fix Version 2.0.1 causes rendering HTML scripts issue #80
253
+
254
+ 2.0.1 (2024-03-02)
255
+ ------------------=
256
+
257
+ * Fixed Version 2.0.0 causes issues with Django 4.x due to missing sourcemaps issue #83
258
+
259
+ 2.0.0 (2024-03-24)
260
+ ------------------
261
+
262
+ * Fix default paths for static files #53
263
+ * Stop declaring support for Django versions before 3.2 #65
264
+ * Avoid HTML injection via unsafe JSON injection #64
265
+ * Remove source map reference from JS bundle #70
266
+ * Add dark mode CSS support #82
267
+ * Updated documentation
268
+
269
+ 1.1.1 (2021-02-17)
270
+ ------------------
271
+
272
+ * Fix for issue #51, updates the bundled libs to 9.1.9 and additional notes for Django 3.1 changes
273
+
274
+ 1.1.0 (2021-02-05)
275
+ ------------------
276
+
277
+ * Added functionality to override version of JSONEditor to use
278
+ * update readme for django 3.1
279
+
280
+ 1.0.1 (2020-04-17)
281
+ ------------------
282
+
283
+ * Stop resolving paths to the static files
284
+
285
+ 1.0.0 (2020-01-16)
286
+ ------------------
287
+
288
+ * Update Makefile
289
+ * Make Stable the project
290
+
291
+
292
+ 0.3.0 (2020-01-16)
293
+ ------------------
294
+
295
+ * Update requirements.txt
296
+ * Fixed static to work with CDN tools like django-storages
297
+ * Make widget more configurable
298
+ * Fixed an incompatibility with Python 2.7
299
+ * update jsoneditor to latest version
300
+
301
+