How to set HTMLField's widget's height in Admin?
Posted
by
Georgie Porgie
on Stack Overflow
See other posts from Stack Overflow
or by Georgie Porgie
Published on 2011-12-21T21:23:08Z
Indexed on
2012/10/22
23:01 UTC
Read the original article
Hit count: 257
I have a HTMLField in a model as it's the laziest way to utilize tinymce widget in Admin. But the problem is that the textarea field doesn't have "rows" property set. So the textarea doesn't have enough height comfortable enough for editing in Admin. Is there any way to set the height of HTMLField without defining a ModelAdmin class?
Update:
I solved the problem by using the following code:
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)
© Stack Overflow or respective owner