views:

4413

answers:

6

I would like to know the best way to replace a standard textarea field with a rich text editor in Django Admin?

+10  A: 

There's an add-on Django application to provide TinyMCE support for Django admin forms without having to muck around with admin templates or Django newform internals.

Niten
+1  A: 

I second Niten's suggestion. Also, have a look at this.

ayaz
+7  A: 

Take a look on this snippet - basic idea is to include custom JS in your admin definitions which will replace standard text areas with rich-text editor.

For jQuery/FCKEditor such JS could look like that:

$(document).ready(function() {
    $("textarea").each(function(n, obj) {
        fck = new FCKeditor(obj.id) ;
            fck.BasePath = "/admin-media/fckeditor/" ;
            fck.ReplaceTextarea() ;
    });
});
vvarp
Interesting. Thanks. TinyMCE was being a bitch with IE, so had to replace it with FCKEditor on Django admin.
ayaz
+1  A: 

I'd say: define your own ModelAdmin class and overwrite the widget used for particular field, like:

class ArticleAdminModelForm(forms.ModelForm):
    description = forms.CharField(widget=widgets.AdminWYMEditor)

    class Meta:
        model = models.Article

(AdminWYMEditor is a forms.Textarea subclass that adds WYMEditor with configuration specific to Django admin app).

See this blog post by Jannis Leidel to see how this widget can be implemented.

zgoda
+1  A: 

Currently the most straight forward way to use tinymce in django admin is to use Grappelli.

http://code.google.com/p/django-grappelli/

Grappelli is also a requirement for django-filebrowser so if you want the whole shebang you will gotta need it anyways.

LastCall_
let's wait for the v3 (maybe standalone of grappelli)..meanwhile i got the bundle working with http://code.google.com/p/django-filebrowser/source/browse/branches/filebrowser3-no-grappelli/ and django-tinymce-1.5.tar.gz (latest release at this time) with this hack http://code.google.com/p/django-tinymce/issues/detail?id=40eh.
LastCall_
A: 

Ok, to update a little this post, I would say that the easiest way to implement TinyMCE is to use the django-tinymce app. You must also download the JS files from the TinyMCE page. I got some errors with the django intenationalization, but downloading the laguage packs from the TinyMCE must be enough.

FernandoEscher