2

我正在使用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')),
4

1 回答 1

13

您需要覆盖内容字段的小部件。去做这个:

  1. FlatpageFormModelForm 扩展为PageForm
  2. 扩展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)
于 2013-03-02T19:58:22.137 回答