Embedding tinyMCE in django flatpage

心已入冬 提交于 2019-12-06 07:11:24

you need to override the widget for the content field. To do this:

  1. extend the FlatpageForm ModelForm as PageForm
  2. extend the FlatPageAdmin to use the new PageForm

code example:

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

then unregister the old flatpage admin and reregister the new one

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, PageAdmin)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!