【问题标题】:How to set HTMLField's widget's height in Admin?如何在 Admin 中设置 HTMLField 小部件的高度?
【发布时间】:2011-12-21 21:23:08
【问题描述】:

我在模型中有一个 HTMLField,因为它是在 Admin 中使用 tinymce 小部件的最懒惰的方式。但问题是 textarea 字段没有设置“rows”属性。所以 textarea 的高度不够舒适,无法在 Admin 中进行编辑。有没有什么方法可以在不定义 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)

【问题讨论】:

    标签: django tinymce django-tinymce


    【解决方案1】:

    在 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

    http://www.tinymce.com/wiki.php/Buttons/controls

    【讨论】:

      【解决方案2】:

      我个人认为在管理表单上设置 media definition on the admin class 来激活 TinyMCE 会更容易。

      但是,要回答您的问题,您可能需要调整表单用于显示该字段的小部件。请参阅文档中的customizing widget instances。您可以将行属性传递给小部件以使其更大。

      【讨论】:

        猜你喜欢
        • 2016-10-12
        • 1970-01-01
        • 2014-09-08
        • 2014-07-25
        • 1970-01-01
        • 1970-01-01
        • 2021-08-26
        • 2021-06-10
        • 1970-01-01
        相关资源
        最近更新 更多