[Solved]-How to integrate wysiwyg editor with django flatpages?

11👍

I just connect django-ckeditor to flatpages application by following code in admin.py:

from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from django.db import models

from cked.widgets import CKEditorWidget

class FlatPageCustom(FlatPageAdmin):
    formfield_overrides = {
        models.TextField: {'widget': CKEditorWidget}
    }

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageCustom)

It works!

0👍

from django.db.models import Field
from django.forms import Textarea
from settings import MEDIA_URL

class WidgetWYSIWYG(Textarea):
    def __init__(self, *args, **kwargs):
        super(WidgetWYSIWYG, self).__init__(attrs={'class': 'wysiwygEditor vLargeTextField'}, *args, **kwargs)
    class Media:
        js = (
            MEDIA_URL+'common/tiny_mce/tiny_mce.js',
            MEDIA_URL+'common/filebrowser/js/TinyMCEAdmin.js',
            )

class WYSIWYGField(Field):
    def get_internal_type(self):
        return "TextField"

    def formfield(self, **kwargs):
        defaults = {'widget': WidgetWYSIWYG}
        defaults.update(kwargs)
        return super(WYSIWYGField, self).formfield(**defaults)

in file admin.py

from django.contrib import admin
from wysiwyg import WidgetWYSIWYG

from django.db import models
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld

class FlatPageAdmin(FlatPageAdminOld):
    formfield_overrides = {
        models.TextField: {'widget': WidgetWYSIWYG},
    }

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)

0👍

I would try this application. It’s using Tiny MCE.

https://github.com/mjr27/django-flatpages-tinymce

👤n1_

Leave a comment