Skip to content

Instantly share code, notes, and snippets.

@RANUX
Forked from elidickinson/admin.py
Created August 31, 2019 06:42
Show Gist options
  • Save RANUX/a4285f99c61accbd864b7e705b4d0183 to your computer and use it in GitHub Desktop.
Save RANUX/a4285f99c61accbd864b7e705b4d0183 to your computer and use it in GitHub Desktop.
Using CKEditor with Flatpages
from django.contrib import admin
from django.contrib.flatpages.models import FlatPage
# Note: we are renaming the original Admin and Form as we import them!
from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld
from django.contrib.flatpages.admin import FlatpageForm as FlatpageFormOld
from django import forms
from ckeditor.widgets import CKEditorWidget
class FlatpageForm(FlatpageFormOld):
content = forms.CharField(widget=CKEditorWidget())
class Meta:
model = FlatPage # this is not automatically inherited from FlatpageFormOld
class FlatPageAdmin(FlatPageAdminOld):
form = FlatpageForm
# We have to unregister the normal admin, and then reregister ours
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment