Tip: Extending Django flatpages

I did a Google search and since nothing came up, I'm writing this little tip on creating your own CMS by extending Django's flatpages. What's good about flatpages is that they're included in Django and has some basic code to get you started. But clearly they're not enough if you want other people to administer a site.. you'll want to add extra fields and special help texts for the admin. But we still don't want to rewrite those ~150 lines of code, and they can really help you get past all the boring stuff and into the action.

Simply do the following:

cp -R /usr/share/python-support/python-django/django/contrib/flatpages my_project/my_flatpages


 from my_project.my_flatpages.models import FlatPage


 from my_project.my_flatpages.views import flatpage


 urlpatterns = patterns('my_project.my_flatpages.views',  
    (r'^(?P.*)$', 'flatpage'),  

my_project.my_flatpages.middleware.FlatpageFallbackMiddleware has to be added to your MIDDLEWARE_CLASSES and my_project.my_flatpages to your INSTALLED_APPS and you'll need to run manage.py syncdb , possibly changing the table name in models.py , so it doesn't conflict with the old flatpages table. That's basically it. After that you can work on the templates as described in the other howto's, but now you have your own model to extend.