djangoueditor 集成xadmin

Posted Erick - LONG

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了djangoueditor 集成xadmin相关的知识,希望对你有一定的参考价值。

1、安装Python3兼容版本

https://github.com/twz915/DjangoUeditor3/

2、model加入字段

from DjangoUeditor.models import UEditorField
class Blog(models.Model):
    Name=models.CharField(,max_length=100,blank=True)
    Content=UEditorField(u内容    ,width=600, height=300, toolbars="full", imagePath="", filePath="", upload_settings={"imageMaxSize":1204000},
          default=‘‘)

3、xadmin/plugins 插入ueditor.py

import xadmin
from xadmin.views import BaseAdminPlugin, CreateAdminView, ModelFormAdminView, UpdateAdminView
from DjangoUeditor.models import UEditorField
from DjangoUeditor.widgets import UEditorWidget
from django.conf import settings


class XadminUEditorWidget(UEditorWidget):
    def __init__(self,**kwargs):
        self.ueditor_options=kwargs
        self.Media.js = None
        super(XadminUEditorWidget,self).__init__(kwargs)


class UeditorPlugin(BaseAdminPlugin):
    #识别ueditor  style_fields
    def get_field_style(self, attrs, db_field, style, **kwargs):
        if style == ueditor:
            if isinstance(db_field, UEditorField):
                widget = db_field.formfield().widget
                param = {}
                param.update(widget.ueditor_settings)
                param.update(widget.attrs)
                return {widget: XadminUEditorWidget(**param)}
        return attrs

    def block_extrahead(self, context, nodes):
        js = <script type="text/javascript" src="%s"></script> % (settings.STATIC_URL + "ueditor/ueditor.config.js")         #自己的静态目录
        js += <script type="text/javascript" src="%s"></script> % (settings.STATIC_URL + "ueditor/ueditor.all.min.js")   #自己的静态目录
        nodes.append(js)

xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)

4、xadmin/plugins/__init__.py加入

ueditor

5、

以上是关于djangoueditor 集成xadmin的主要内容,如果未能解决你的问题,请参考以下文章

xadmin集成DjangoUeditor,以及编辑器的视频路径配置

django xadmin 集成DjangoUeditor富文本编辑器

Django中在xadmin中集成DjangoUeditor

第三百九十四节,Django+Xadmin打造上线标准的在线教育平台—Xadmin集成富文本框

django学习——xadmin中集成富文本编辑器ueditor

xadmin 插件开发