Alex Rivera | Logout

Django Admin: Add TinyMCE to particular TextField only?

Asked 2010-10-14T10:09:22.503
9

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
Report

1 Answer

10

Right, if anyone is looking to do this:

First make sure the tinymce settings are correct:

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 ProductionForm(forms.ModelForm):
    some_field = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))

    class Meta:
        model = Production

class ProductionAdmin(admin.ModelAdmin):
    form = ProductionForm
answered 2011-05-31T02:08:25.203

Your Answer