0

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?

rush
  • 2,484
  • 2
  • 19
  • 31

2 Answers2

1

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.

Brandon Taylor
  • 33,823
  • 15
  • 104
  • 144
0

On a field by field basis you can use this technique providing a custom ModelForm:

class XAdminForm(forms.ModelForm):
    name = forms.CharField(label='Name', max_length=100,
                    widget=forms.TextInput(attrs={'size': '100'}))
    something = forms.CharField(label='Something', max_length=SOME_MAX_LENGTH,
                      widget=forms.Textarea(attrs={'rows': '10', 'cols': '100'}))
    note = forms.CharField(label='Note', max_length=NOTE_MAX_LENGTH,
                   widget=forms.Textarea(attrs={'class': 'ckeditor'}))
class Meta:
    model = x

class Meta:
    model = x


class XAdmin(admin.ModelAdmin):
    model = X
    form = XAdminForm

    class Media:
        js = ('/static/js/ckeditor/ckeditor.js',)
admin.site.register(X, XAdmin)
rbell01824
  • 189
  • 4
  • 10