Search code examples
djangodjango-admintinymcedjango-tinymce

django admin tinymce for part of textareas


I'm using django admin + grappelli + tinymce from grappelli.

It works perfect, but I can't figure out how to make an admin form with textareas and apply tinymce only for part of them.

For example, I've two fields: description and meta-description. I need tinymce only for description and I need textarea without tinymce for meta-descrption.

tinymce in admin is enabled via form like this:

class AdminForm(forms.ModelForm):      
    def __init__(self, *args, **kwargs):      
        """Sets the list of tags to be a string"""      
        instance = kwargs.get('instance', None)
        if instance:
            init = kwargs.get('initial', {})
            kwargs['initial'] = init

        super(AdminForm, self).__init__(*args, **kwargs)
    class Media:
            js = (
                     settings.STATIC_URL + 'grappelli/tinymce/jscripts/tiny_mce/tiny_mce.js',
                     settings.STATIC_URL + 'grappelli/tinymce_setup/tinymce_setup.js',
            ) 

and enabled in admin.py:

class ModelAdmin(admin.ModelAdmin):
    form = AdminForm

It looks like behaviour is described in the beginning of tinymce init:

tinyMCE.init({
    mode: 'textareas',
    theme: 'advanced',
    skin: 'grappelli',
    ...

Is there a way to solve my issue?


Solution

  • By setting the mode to textareas, it won't give you any sort of selector control as to which one it applies the editor to. You'll most likely need to drop the mode setting and go with selector: http://www.tinymce.com/wiki.php/Configuration:selector

    The django-tinymce config options are just a mirror for TinyMCE's settings.