Skip to main content

Django plugin for using Editor.js in admin

Project description

django-editorjs

GitHub version PyPi downloads

Plugin for using Editor.js in django admin.

Supported tools

  • @editorjs/paragraph - npm version
  • @editorjs/image - npm version
  • @editorjs/header - npm version
  • @editorjs/checklist - npm version
  • @editorjs/list - npm version
  • @editorjs/quote - npm version
  • @editorjs/raw - npm version
  • @editorjs/embed - npm version
  • @editorjs/delimiter - npm version
  • @editorjs/warning - npm version
  • @editorjs/link - npm version
  • @editorjs/marker - npm version
  • @editorjs/attaches - npm version
  • @editorjs/table - npm version

Installation

  1. First step is install plugin.
    pip install django-editorjs
    
  2. Add plugin to INSTALLED_APPS in Django settings file.
    # settings.py
    INSTALLED_APPS = [
        # some other apps
        'django_editorjs'
    ]
    
  3. 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 tool ImageTool. (For more info see official documentation for tool).
    • Header - (dict) configuration for tool Header. (For more info see official documentation for tool).
    • Checklist - (dict) configuration for tool Checklist. (For more info see official documentation for tool).
    • List - (dict) configuration for tool List. (For more info see official documentation for tool).
    • Quote - (dict) configuration for tool Quote. (For more info see official documentation for tool).
    • Raw - (dict) configuration for tool RawTool. (For more info see official documentation for tool).
    • Embed - (dict) configuration for tool Embed. (For more info see official documentation for tool).
    • Delimiter - (dict) configuration for tool Delimiter. (For more info see official documentation for tool).
    • Warning - (dict) configuration for tool Warning. (For more info see official documentation for tool).
    • Link - (dict) configuration for tool LinkTool. (For more info see official documentation for tool).
    • Marker - (dict) configuration for tool Marker. (For more info see official documentation for tool).
    • Attaches - (dict) configuration for tool AttachesTool. (For more info see official documentation for tool).
    • Table - (dict) configuration for tool Table. (For more info see official documentation for tool).

API

  • EditorJsField

    Extends TextField and use EditorJsWidget 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-editorjs-1.0a2.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

django_editorjs-1.0a2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file django-editorjs-1.0a2.tar.gz.

File metadata

  • Download URL: django-editorjs-1.0a2.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

Hashes for django-editorjs-1.0a2.tar.gz
Algorithm Hash digest
SHA256 6bfc7a8ff4396280c1e7a663c9107a60b7ce58f0e4d8058ca953a9f907f455c1
MD5 9b2eb5475fa36f3961e0ed367a7a764d
BLAKE2b-256 8204337ce7ec024b5c19e0337fabbeadde5282015ce56ca186ce2b47edd1105c

See more details on using hashes here.

File details

Details for the file django_editorjs-1.0a2-py3-none-any.whl.

File metadata

  • Download URL: django_editorjs-1.0a2-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

Hashes for django_editorjs-1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 9304d1feadd28870a858aa0757b0b31728acd79fd0efb9c119a71d517e2a45c9
MD5 3da3d36720208653cfe8c34aeff13659
BLAKE2b-256 226c2cd4a03fd28b036f32588de4af0cde79ab2cdcf8bab96d2450ab9540e3df

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page