Embedding tinyMCE in django flatpage

谁说胖子不能爱 提交于 2019-12-22 12:13:30

问题


I'm using django-tinymce. I'd like to know how to embed it in a flatpage in admin panel.

From the project's readme:

Add tinymce to INSTALLED_APPS in settings.py for your project:

INSTALLED_APPS = (
    ...
    'tinymce',
)

Add tinymce.urls to urls.py for your project:

urlpatterns = patterns('',
    ...
    (r'^tinymce/', include('tinymce.urls')),
)

My flatpage url :

url(r'^pages/', include('django.contrib.flatpages.urls')),

回答1:


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)


来源:https://stackoverflow.com/questions/15123927/embedding-tinymce-in-django-flatpage

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