我在模型中有一个 HTMLField,因为这是在管理中使用 tinymce 小部件的最懒的方式。但问题是 textarea 字段没有设置“rows”属性。因此,文本区域的高度不够舒适,无法在管理中进行编辑。有没有办法在不定义 ModelAdmin 类的情况下设置 HTMLField 的高度?
更新:
我使用以下代码解决了这个问题:
def create_mce_formfield(db_field):
return db_field.formfield(widget = TinyMCE(
attrs = {'cols': 80, 'rows': 30},
mce_attrs = {
'external_link_list_url': reverse('tinymce.views.flatpages_link_list'),
'plugin_preview_pageurl': reverse('tinymce-preview', args= ('tinymce',)),
'plugins': "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
'theme_advanced_buttons1': "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
'theme_advanced_buttons2': "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
'theme_advanced_buttons3': "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
'theme_advanced_buttons4': "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
'theme_advanced_toolbar_location': "top",
'theme_advanced_toolbar_align': "left",
'theme_advanced_statusbar_location': "bottom",
'theme_advanced_resizing': True,
'extended_valid_elements': "iframe[src|title|width|height|allowfullscreen|frameborder|webkitAllowFullScreen|mozallowfullscreen|allowFullScreen]",
},
))
class TinyMCEFlatPageAdmin(FlatPageAdmin):
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'content': return create_mce_formfield(db_field)
return super(TinyMCEFlatPageAdmin, self).formfield_for_dbfield(db_field, **kwargs)
在settings.py中
TINYMCE_DEFAULT_CONFIG = {
'plugins': "table,xhtmlxtras,paste,searchreplace",
'theme': "advanced",
"theme_advanced_buttons3_add" : "cite,abbr",
'cleanup_on_startup': True,
'custom_undo_redo_levels': 10,
}
所有选项:
http://www.tinymce.com/wiki.php/Configuration:Advanced_theme