如何在Wagtail CMS中使用WYSIWYG编辑器?

时间:2019-01-07 18:02:46

标签: django wagtail

我正在尝试将Wagtail CMS与我现有的Django项目集成在一起。除了this basic installation,我制作了一个名为wagtail_hooks.py的文件。到目前为止,一切都很好,但是我需要在Wagtail CMS上使用WYSIWYG编辑器。是否可以访问Wagtail的models.py,以便我可以在模型级别使用第三方WYSIWYG编辑器?

MY_APP / wagtail_hooks.py

from wagtail.contrib.modeladmin.options import (
    ModelAdmin, modeladmin_register)
from .models import Store


class StoreAdmin(ModelAdmin):
    model = Store
    menu_label = 'Store'  # ditch this to use verbose_name_plural from model
    menu_icon = 'doc-full'  # change as required
    menu_order = 10  # will put in 3rd place (000 being 1st, 100 2nd)
    add_to_settings_menu = False  # or True to add your model to the Settings sub-menu
    exclude_from_explorer = False  # or True to exclude pages of this type from Wagtail's explorer view
    list_display = ['id', 'status', 'typ', 'businessName',]
    search_fields = ('businessName', 'created_by__username',)


# Now you just need to register your customised ModelAdmin class with Wagtail
modeladmin_register(StoreAdmin)

1 个答案:

答案 0 :(得分:1)

Wagtail附带了一个出色的WYSIWYG编辑器Draftail,它基于DraftJS。它是高度可扩展的:

http://docs.wagtail.io/en/v2.4/advanced_topics/customisation/extending_draftail.html

要使用它,可以将模型更改为使用wagtail.core.fields.RichTextField代替TextField

还有其他几种所见即所得的编辑器,例如,您仍然可以在此设置下使用旧的编辑器:

WAGTAILADMIN_RICH_TEXT_EDITORS = {
    'default': {
        'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea'
    }
}

祝你好运!