flatpage admin widget
posted on july 15th in django
This doesn't work correctly
The yui-js breaks some of django's admin js (collapse divs etc)
I use tinymce and the yui-richtext editor in django projects quite a bit. I prefer plain text, but clients don't. Anyway I utilize flatpages quite a bit and need a way to wrap flatpages with the proper widget. if you have one main app (which you shouldn't), just throw this in the admin.py. The better way is to put this in its own app or in some utility app that contains a few things like this.
# admin.py
from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from richtext.custom_widgets.py import RichTextWidget # This uses django-richtext
class CustomFlatPageAdmin(FlatPageAdmin):
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'content':
return db_field.formfield(widget=RichTextWidget())
return super(FlatPageAdmin, self).formfield_for_dbfield(db_field, **kwargs)
# We have to unregister it, and then reregister
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, CustomFlatPageAdmin)