Skip to content

Commit 002e2d5

Browse files
committed
README.md
1 parent cf1860e commit 002e2d5

File tree

6 files changed

+97
-5
lines changed

6 files changed

+97
-5
lines changed

README.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,92 @@
11
# Editor.js for Django
2-
Django plugin for using Editor.js
2+
3+
Django plugin for using [Editor.js](https://editorjs.io/)
4+
5+
> This plugin works fine with JSONField in Django >= 3.1
6+
7+
## Installation
8+
9+
```bash
10+
pip install django-editorjs
11+
```
12+
13+
Add django_editorjs to INSTALLED_APPS in settings.py for your project:
14+
```python
15+
# settings.py
16+
INSTALLED_APPS = [
17+
...
18+
'django_editorjs',
19+
]
20+
```
21+
22+
## Usage
23+
24+
Add code in your model
25+
```python
26+
# models.py
27+
from django.db import models
28+
from django_editorjs import EditorJsJSONField, EditorJsTextField # import
29+
30+
31+
class Post(models.Model):
32+
body_default = models.TextField()
33+
body_editorjs = EditorJsJSONField() # Django >= 3.1
34+
body_editorjs_text = EditorJsTextField() # Django <= 3.0
35+
36+
```
37+
38+
Or add custom Editor.js plugins and configs ([List plugins](https://github.com/editor-js/awesome-editorjs))
39+
40+
```python
41+
# models.py
42+
from django.db import models
43+
from django_editorjs import EditorJsJSONField, EditorJsTextField # import
44+
45+
46+
class Post(models.Model):
47+
body_custom = EditorJsJSONField(
48+
plugins=[
49+
"@editorjs/image",
50+
"@editorjs/header",
51+
"editorjs-github-gist-plugin",
52+
"@editorjs/code@2.6.0", # version allowed :)
53+
"@editorjs/list@latest",
54+
"@editorjs/inline-code",
55+
"@editorjs/table",
56+
],
57+
tools={
58+
"Image": {
59+
"config": {
60+
"endpoints": {
61+
# Your custom backend file uploader endpoint
62+
"byFile": "/editorjs/image_upload/"
63+
}
64+
}
65+
}
66+
},
67+
null=True,
68+
blank=True
69+
)
70+
71+
```
72+
73+
If you want to upload images to the editor then add django_editorjs.urls to urls.py for your project:
74+
```python
75+
# urls.py
76+
from django.contrib import admin
77+
from django.urls import path, include
78+
from django.conf import settings
79+
from django.conf.urls.static import static
80+
81+
urlpatterns = [
82+
path('admin/', admin.site.urls),
83+
path('editorjs/', include('django_editorjs.urls')),
84+
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
85+
```
86+
87+
See an example of how you can work with the plugin [here](https://github.com/2ik/django-editorjs/blob/main/example)
88+
89+
90+
## Support and updates
91+
92+
Use github issues https://github.com/2ik/django-editorjs/issues

django_editorjs/fields.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
try:
1010
# pylint: disable=ungrouped-imports
11-
from django.db.models import JSONField
11+
from django.db.models import JSONField # Django >= 3.1
1212
except ImportError:
1313
HAS_JSONFIELD = False
1414
else:
1515
HAS_JSONFIELD = True
1616

17+
__all__ = ['EditorJsTextField', 'EditorJsJSONField']
18+
1719

1820
class FieldMixin(Field):
1921
def get_internal_type(self):

django_editorjs/static/django-editorjs.css renamed to django_editorjs/static/admin/2ik/django-editorjs/css/django-editorjs.css

File renamed without changes.

django_editorjs/static/django-editorjs.js renamed to django_editorjs/static/admin/2ik/django-editorjs/js/django-editorjs.js

File renamed without changes.

django_editorjs/widgets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def media(self):
4242
js_list.append('https://cdn.jsdelivr.net/combine/npm/' +
4343
',npm/'.join(plugins))
4444

45-
js_list.append('django-editorjs.js')
45+
js_list.append('admin/2ik/django-editorjs/js/django-editorjs.js')
4646

4747
return Media(
48-
css={'all': ['django-editorjs.css']},
48+
css={'all': ['admin/2ik/django-editorjs/css/django-editorjs.css']},
4949
js=js_list
5050
)
5151

example/example/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,5 @@
132132

133133
STATIC_URL = '/static/'
134134
MEDIA_URL = "/media/"
135-
STATIC_URL = f'{BASE_DIR}/static/'
135+
STATIC_ROOT = f'{BASE_DIR}/static/'
136136
MEDIA_ROOT = f'{BASE_DIR}/media/'

0 commit comments

Comments
 (0)