[Django]-Django โ€“ TinyMCE โ€“ admin โ€“ How to change editor size?

10๐Ÿ‘

โœ…

As said in the docs (http://django-tinymce.readthedocs.io/en/latest/installation.html#configuration), there is the TINYMCE_DEFAULT_CONFIG setting which can be used to configure the editor. Just look for available options here: https://www.tinymce.com/docs/configure/editor-appearance/.

In your case, I think something like this may work:

TINYMCE_DEFAULT_CONFIG = {
    'theme': "simple", # default value
    'relative_urls': False, # default value
    'width': '100%',
    'height': 300
}

Put it in your settings.py

๐Ÿ‘คabidibo

2๐Ÿ‘

TINYMCE_DEFAULT_CONFIG dictionary needs to set in the settings.py file.

TINYMCE_DEFAULT_CONFIG = {
    'theme': "advanced",
    'width' : 758,
    'height' : 118,
}

This will change width and height of the tinymce editor.

๐Ÿ‘คBasant Kumar

0๐Ÿ‘

I wanted to do exactly this โ€“ change the TinyMCE admin widget size โ€“ but not change the whole/default configuration for all of the widgets. Here was my solution:

class SomeModelClassAdmin(admin.ModelAdmin):
    # ...
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == "description":
            return db_field.formfield(
                widget=TinyMCE(
                    mce_attrs={"height": "200"},
                )
            )
        return super().formfield_for_dbfield(db_field, **kwargs)

TLDR: in your admin.py, within the model admin class, override formfield_for_dbfield with the above.

This only changes the height for the model field called description rather than all admin tinycme widgets. Hope this can be useful! It took me a while to figure it out ๐Ÿ™‚

๐Ÿ‘คGreg Sadetsky

Leave a comment