Django plugin for using Editor.js in admin
Project description
django-editorjs
Plugin for using Editor.js in django admin.
Supported tools
@editorjs/paragraph
-@editorjs/image
-@editorjs/header
-@editorjs/checklist
-@editorjs/list
-@editorjs/quote
-@editorjs/raw
-@editorjs/embed
-@editorjs/delimiter
-@editorjs/warning
-@editorjs/link
-@editorjs/marker
-@editorjs/attaches
-@editorjs/table
-
Installation
- First step is install plugin.
pip install django-editorjs
- Add plugin to INSTALLED_APPS in Django settings file.
# settings.py INSTALLED_APPS = [ # some other apps 'django_editorjs' ]
- Register plugin's endpoints in in
urlpatterns
# urls.py from django_editorjs.urls import urlpatterns urlpatterns = [ # other urls *urlpatterns ]
Simple example
# models.py
from django.db import models
from django_editorjs import EditorJsField
class Post(models.Model):
title = models.CharField(max_length=255)
body = EditorJsField()
def __str__(self):
return self.title
Configuration
Base configuration
This plugin provides additional functionality for saving images and files + allow to get information about some link.
You can to configure some options in your settings.py
file.
EDITORJS_IMAGES_FOLDER
- Default folder for keep images uploaded through EditorJs (Default:{MEDIA_ROOT}/editorjs
)EDITORJS_FILES_FOLDER
- Default folder for keep files uploaded through EditorJs (Default:{MEDIA_ROOT}/editorjs
)
How to configure fields
⚠️ Note (for plugin configuration)
Usually in examples for Editor.js you will see tool names starts with lowercase, but for bypass potential conflicts i name tools with capital letters.
You can provide field specific configuration options to EditorJsField
by argument editorjs_config
.
Example
class Post(models.Model):
title = models.TextField()
body = EditorJsField(
editorjs_config={
"tools": {
"Table": {
"disabled": False,
"inlineToolbar": True,
"config": {"rows": 2, "cols": 3,},
}
}
}
)
Config schema
tools
Image
- (dict
) configuration for toolImageTool
. (For more info see official documentation for tool).Header
- (dict
) configuration for toolHeader
. (For more info see official documentation for tool).Checklist
- (dict
) configuration for toolChecklist
. (For more info see official documentation for tool).List
- (dict
) configuration for toolList
. (For more info see official documentation for tool).Quote
- (dict
) configuration for toolQuote
. (For more info see official documentation for tool).Raw
- (dict
) configuration for toolRawTool
. (For more info see official documentation for tool).Embed
- (dict
) configuration for toolEmbed
. (For more info see official documentation for tool).Delimiter
- (dict
) configuration for toolDelimiter
. (For more info see official documentation for tool).Warning
- (dict
) configuration for toolWarning
. (For more info see official documentation for tool).Link
- (dict
) configuration for toolLinkTool
. (For more info see official documentation for tool).Marker
- (dict
) configuration for toolMarker
. (For more info see official documentation for tool).Attaches
- (dict
) configuration for toolAttachesTool
. (For more info see official documentation for tool).Table
- (dict
) configuration for toolTable
. (For more info see official documentation for tool).
API
-
EditorJsField
Extends
TextField
and useEditorJsWidget
as widget + have additional argument in constructor:editorjs_config
. -
EditorJsWidget
Widget that you can to use for using Editor.js in Django.
Custom ImageSaver
ImageSaver
is class for saving images on disk. You can to create custom saver. Custom saver must implement this interface:
class ImageSaver:
save(file: File) -> ImageSaveResult
after creating class you can to change option EDITORJS_IMAGES_SAVER
in settings to somethink like:
# settings.py
EDITORJS_IMAGES_SAVER = "your_app.your_module.YourImageSaverClass"
Custom FileSaver
Similary to ImageSaver
you can to create custom FileSaver
class with this interface:
class FileSaver:
save(file: File) -> FileSaveResult
How to run demo
poetry install
poetry run python ./demo/manage.py migrate
poetry run python ./demo/manage.py createsuperuser
poetry run python ./demo/manage.py runserver
TODO
- load tool on demand
- more examples in README.md
- view-function for file uploading
- view-function for image uploading
- view-function for link info crawler
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
Built Distribution
File details
Details for the file django-editorjs-1.0a1.tar.gz
.
File metadata
- Download URL: django-editorjs-1.0a1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fe15b2ce3a43d31474aa2e0412ffd981e0c143278cdb695b12c30ae96c28bc4 |
|
MD5 | bab0c29a4bab6a248cbef674b4f8734f |
|
BLAKE2b-256 | 008dbfaebba89574fe9bfbf649d128f32b3b2f5dbe98e7e6a1c2403dfc73f6d7 |
File details
Details for the file django_editorjs-1.0a1-py3-none-any.whl
.
File metadata
- Download URL: django_editorjs-1.0a1-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c4521010486fea69cb05cbbea6c63f772aa106cd451429fdda9da3171d43e82 |
|
MD5 | c5bf924c0aab4577c6ea3fc1b3591628 |
|
BLAKE2b-256 | a071e43d8d83c8993eb2d212c695e3ffb3c913811459f301fd61c35b78bf5e39 |