class XadminUEditorWidget(UEditorWidget):
def __init__(self,**kwargs):
self.ueditor_options=kwargs
self.Media.js = None
super(XadminUEditorWidget,self).__init__(kwargs)
self.Media.js = None注釋掉湾揽,UEditor不正常。不注釋,m2m不正常踢关。
解決方案:
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
# 添加到footer
def get_media(self, media):
media = media + self.vendor('xadmin.widget.select.js', 'xadmin.widget.select-transfer.js',
'xadmin.plugin.quick-form.js')
return media
# 在我們生成的頁(yè)面中放入自己的js文件伞鲫,添加到header
def block_extrahead(self, context, nodes):
# m2m_transfer和ueditor js沖突解決
js = '<link href="/static/xadmin/vendor/select2/select2.css" type="text/css" media="screen" rel="stylesheet">'
js += '<link href="/static/xadmin/vendor/selectize/selectize.css" type="text/css" media="screen" rel="stylesheet">'
js += '<link href="/static/xadmin/vendor/selectize/selectize.bootstrap3.css" type="text/css" media="screen" rel="stylesheet">'
js += '<link href="/static/xadmin/css/xadmin.widget.select-transfer.css" type="text/css" media="screen" rel="stylesheet">'
js += '<script type="text/javascript" src="/static/xadmin/vendor/selectize/selectize.js"></script>'
js += '<script type="text/javascript" src="/static/xadmin/vendor/select2/select2.js"></script>'
js += '<script type="text/javascript" src="/static/xadmin/vendor/select2/select2_locale_zh-hans.js"></script>'
# js += '<script type="text/javascript" src="/static/xadmin/js/xadmin.widget.select.js"></script>'
# js += '<script type="text/javascript" src="/static/xadmin/js/xadmin.widget.select-transfer.js"></script>'
# js += '<script type="text/javascript" src="/static/xadmin/js/xadmin.plugin.quick-form.js"></script>'
js += '<script type="text/javascript" src="%s"></script>' % (settings.STATIC_URL + "ueditor/ueditor.config.js") #自己的靜態(tài)目錄
js += '<script type="text/javascript" src="%s"></script>' % (settings.STATIC_URL + "ueditor/ueditor.all.min.js") #自己的靜態(tài)目錄
nodes.append(js)
## 新增頁(yè)面
xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
## 修改頁(yè)面
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)
~~~python
get_media將這三個(gè)js放在get_media方法中。一定放在footer签舞!加在下面的header中無(wú)用秕脓。
在block_extrahead中放入對(duì)比后差的css和js文件。
運(yùn)行成功儒搭。