Django’s admin html editor — TinyMCE


get TinyMCE running inside Django's Admin
1. craete /usr/lib/python2.5/site-packages/django/contrib/admin/media/tiny_mce (for linux)
2. download TinyMCE (should be like this figure 1)
3. Configure the TinyMCE pane. In the django/contrib/admin/media/js folder, add a textareas.js file that will initialize and configureTinyMCE.
4. textareas.js
5. write a page in model.p
6. add
js = ['tiny_mce/tiny_mce.js', 'js/textareas.js'] at the end
Reference for using js in admin page: http://www.djangoproject.com/documentation/model-api/#j
class Admin:

fields = (

('Content', {'fields': ('name','position','bio','fote', 'jobcat', 'pageorder')}),
)

list_display = ( 'name', 'jobcat' )
list_filter = ['status', 'jobcat']

search_fields = ['name']

js = ['tiny_mce/tiny_mce.js', 'js/textareas.js']

7. further:The next thing I want to do is install TinyMCE as the default DjangoFlatpage editor;
that will require patching the existing admin module,and probably adding a flag to settings.py
to enable/disable it. Itwould be nice too if the setting was global instead of having to markupeach
model's Admin class. The only way I've seen to do that to date is to create a new model field called RichTextField
that brings in the js editor by default. But that mixes up content authoring concerns with modelling
concerns by subclassing forms.TextField, which is why I decided not to go that route. I think hacking
the Admin module to be wysiwyg configurable is cleaner, the problem is deciding what js tool to bundle.
In the long run I imagine admin will ship with Dojo editor since Dojo is what the Django guyshave settled
on (and Dojo editor can deal with the back button as well which is *very* cool).

Reference:http://www.dehora.net/journal/2006/05/using_tinymce_in_djangos_admin.html
http://code.djangoproject.com/wiki/AddWYSIWYGEditor

This entry was posted on December 26, 2007 at 10:28 am

posted @ 2007-12-26 16:26  xxd  阅读(564)  评论(0编辑  收藏  举报