xadmin 插件开发

xadmin 插件开发


互文本编辑器,UEditor 在github上面搜索djangoueditor,经行安装下载
插件官方文档 网址:http://xadmin.readthedocs.io/en/docs-chinese/plugins.html#
安装流程:
1. pip install DjangoUeditor
2.settings.py 中加入DjangoUeditor

3.在adminx.py文件里面,courseAdmin类里面加入
def save_models(self):
obj = self.new_obj
obj.save()
if obj.course_org is not None:
course_org = obj.course_org
course_org.course_nums = Courses.objects.filter(course_org=course_org).count()
course_org.save()
4.在models里面填入
from DjangoUeditor.models import UEdiitorField
修改该类中的字段内容
detail = UEditorField(verbose_name=u'课程详情',width=600, height=300, imagePath="courser/ueditor/", filePath="courser/ueditor/", default='')



3.url(r'ueditor/',include('DjangoUeditor.urls'))
在经行这一步时,会报错,需要修改源码
修改DjangoUeditor\urls.py文件中的,
第4行  将from django.conf.urls import patterns, url 改为  from django.conf.urls import url, include
第10行 将

urlpatterns = patterns('',
    url(r'^controller/$',get_ueditor_controller)
)
改为:
urlpatterns = [
url(r'^controller/$',get_ueditor_controller),
]

在需要修改的app里面的models里面的需要添加ueditor的字段修改为以下字段
4.detai = UEditorField()

5.在\extra_apps\xadmin\plugins下,添加一个文件 ueditor.py
在文件里面填写
# coding=utf-8
import xadmin
from django.db.models import TextField
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):
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(selfself,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)
6.在adminx.py 中,在该类下面添加
style_fields = {"detail":"ueditor"}
7.在\extra_apps\xadmin\plugins下的__init__.py文件中,将'ueditor'其添加在后面
8.在前端页面里面 {% autoescape off %}    {% endautoescape %}

转载于:https://www.cnblogs.com/chenyang13677/p/7768009.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值