我正在使用django-tinymce。我想知道如何将其嵌入管理面板的平面页面中。
从项目的自述文件:
为您的项目在settings.py中添加tinymce到INSTALLED_APPS:
INSTALLED_APPS = (
...
'tinymce',
)
为项目添加tinymce.urls到urls.py:
urlpatterns = patterns('',
...
(r'^tinymce/', include('tinymce.urls')),
)
我的平面网址:
url(r'^pages/', include('django.contrib.flatpages.urls')),
答案 0 :(得分:13)
您需要覆盖内容字段的小部件。要做到这一点:
FlatpageForm
ModelForm扩展为PageForm
FlatPageAdmin
以使用新的PageForm
代码示例:
from django.contrib.flatpages.admin import FlatpageForm, FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
## OOPS this is a custom widget that works for initializing
## tinymce instances on stacked and tabular inlines
## for flatpages, just use the tinymce packaged one.
#from content.widgets import TinyMCE
from tinymce.widgets import TinyMCE
class PageForm(FlatpageForm):
class Meta:
model = FlatPage
widgets = {
'content' : TinyMCE(attrs={'cols': 100, 'rows': 15}),
}
class PageAdmin(FlatPageAdmin):
"""
Page Admin
"""
form = PageForm
然后取消注册旧的平面管理员并重新注册新的
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, PageAdmin)