views:

35

answers:

1

Hello, I have set up TinyMCE to work with the Admin panel (as per the instructions in the Django Docs http://code.djangoproject.com/wiki/AddWYSIWYGEditor )

The problem is that I have Inlines and other text areas within my model for which I don't want TinyMCE to render

Does anyone know how to set TinyMCE to only load for particular fields within my model?

Thanks

EDIT Ok, so I've installed django-tinymce and configured it

I have created the following in the admin.py of the model with the field I want to add tinymce to:

class FooAdminForm(forms.ModelForm):
    class Meta:
        model = Foo

    def __init__(self, *args, **kwards):
        self.bar = forms.TextField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
        super(FooAdminForm, self).__init__(*args, **kwargs)

Unfortunately this still isn't working

EDIT 2 Right, if anyone is looking to do this (and is as clueless as i am!)

First make sure the tinymce settings are correct (I neglected this!)

TINYMCE_JS_ROOT = '/media/tiny_mce/'
TINYMCE_JS_URL = os.path.join(MEDIA_URL, "tiny_mce/tiny_mce_src.js")
TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,spellchecker,paste,searchreplace",
    'theme': "advanced",
}
TINYMCE_SPELLCHECKER = True

Then in the admins.py of your model

from django.forms import *
from django.db.models import *
from tinymce.widgets import TinyMCE

class FooAdminForm(forms.ModelForm):
    foobar = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))

    class Meta:
        model = Foo

class ProductionAdmin(admin.ModelAdmin):
    form = FooAdminForm

I don't know much about forms so maybe someone can comment, but you can't use forms.TextField in the form, it has to be CharField

+2  A: 

That wiki page is about five years old (!) and these days there's a much easier way of integrating TinyMCE, by simply using the django-tinymce project.

However, since you've already done it this way, you can achieve what you want with a simple change to the textareas.js script. The method described at your link uses mode: textareas, which as you note converts all textareas automatically. What you want is this:

mode: "exact",
element: "id_mytextarea",

where "id_mytextarea" is the HTML ID of the field you do want to convert - usually the name of the model field prefixed by "id_". See the TinyMCE documentation.

Daniel Roseman
haha, I actually used the django-docs (without checking the date) as I though they would be more reliable. I've install django-tinymce now. I need to overwrite the admin form model and overwrite the field I want to use the TinyMCE widget?
pastylegs