Django TinyMCEWrapper v 0.4.2¶
About¶
We created Django TinyMCEWrapper to allow us to enable a TinyMCE widget on various third-party Django apps’ ModelAdmin, without having to fork the apps or re-do their ModelAdmin.
The process is flexible, simple and harmless. Django-TinyMCEWrapper redefines the ModelAdmin class after all admin classes are registered and overrides the widget used for the configured fields.
Contents¶
Installation¶
Install using
pip
.pip install django-tinymcewrapper
Add
tinymcewrapper
to your project’sINSTALLED_APPS
.INSTALLED_APPS = ( # ... other apps 'tinymce', 'tinymcewrapper', )
Dependencies¶
Getting Started¶
- Install django-tinymcewrapper and django-tinymce.
- Configure django-tinymce
- Configure django-tinymcewrapper
Configuration¶
The ADMIN_FIELDS
setting is a dictionary in the format {'app.model': <field configuration>}
. There are two methods to specify field configuration: simple and custom.
Simple Configuration¶
The field configuration in the simple configuration is simply a tuple
of strings containing the fields to add a TinyMCE widget in the admin. These fields will use all the defaults for django-tinymce.
TINYMCEWRAPPER_SETTINGS = {
'ADMIN_FIELDS': {
'simpleapp.simplemodel': ('description', 'long_description')
},
}
Custom Configuration¶
For more control over how the TinyMCE widget is rendered, you can use a dict
with the field names as keys and the value a dict
that is passed as keyword arguments to the TinyMCE HTML widget.
TINYMCEWRAPPER_SETTINGS = {
'ADMIN_FIELDS': {
'simpleapp.simplemodel': {
'description': {
'attrs': {'cols': 80, 'rows': 30,},
'mce_attrs': {'theme': 'advanced'}
},
'long_description': {},
}
},
}
Reference¶
Settings¶
ADMIN_FIELDS¶
ADMIN_FIELDS is a dictionary in the format {'app.model': <field configuration>}
. <field configuration>
is either a list
or tuple
{'app.model': ('field', 'field2',),}
or the <field configuration>
is a dict
.
{'app.model': {
'field1': {
'attrs': {'cols': 80, 'rows': 30},
'mce_attrs': {'theme': 'advanced'}
},
'field2': {} # default configuration
}}
For more information see Configuration.