django: disable tinymce for one certain field

990 views Asked by At

I have a lot of models with tinymce(django-tinymce) enabled by default for TextFields and this is ok. But for one field I don't want to apply tinymce widget (in admin interface). Please tell me how do I implement that?

    class Page(models.Model):
        one = models.TextField()
        two = models.TextField()
        three = models.TextField()
2

There are 2 answers

1
karthikr On BEST ANSWER

Yes, In your TinyMCE.init(), you would do:

tinyMCE.init({
        ...
        editor_deselector : "mceNoEditor"
});

and add the class mceNoEditor to the textarea you want to disable tinymce on.

Here is the relevant documentation

In your example, if you want to disable it on three,

three = models.TextField(widget=form.Textarea(attrs={"class": "mceNoEditor"}))
0
Sandy On

First make sure the tinymce settings are properly configure.

tinymce.init({
         editor_deselector : /(highlight|disablemce)/
 })

in my case "editor_deselector" has the above option.

Using admin forms to disable the tinymce option for a particular textField. First you need to import:

from django.forms import TextInput, Textarea
from django.db import models

and then

class MyForm(forms.ModelForm):
   class Meta:
         model:MyModel
   three = forms.CharField(widget=forms.Textarea(attrs={'rows':5, 'cols':80, 'style':"width: 610px;","class": "disablemce"}))

class MyModelAdmin(ModelAdmin):
   model: MyModel
   form: MyForm

If you want to resize your textArea field then you simply add the 'rows':5, 'cols':80, in your attrs options, also you want to add the width then adjust 'style':"width: 610px;" in your attrs options.