Search code examples
djangodjango-flatpages

How can you have Wordpress-like custom fields using Django flatpages?


One of the features that makes a CMS like WordPress powerful is the ability to add additional fields that may be used in the template. WordPress has what it calls custom fields. Is there a way to do that using Django's flat pages? If not, is there another Django app that will allow page creation with the option of adding additional fields?


Solution

  • You could roll your own version of the flatpages app; take a look at the source code, it's really simple.

    It sounds like you could accomplish what you want with two models: one to represent the Pages, and another to represent CustomFields. Tie them together with foreign keys and some inline admin goodness, and you should be set. To access the fields in your template, make sure the Page class implements some kind of lookup function, like __getitem__.