I’m building a small site framework for a set of sites that are likely to have quite a few unstructured pages – meaning they have:
- Slightly different layouts per page
- Lots of one-off text
- None/very little generated content from models
I would like to allow clients to edit the content of these pages through my admin UI (I’m using Django for this project), but with the requirement that they are not exposed to the page HTML and are only able to edit parts of the page that I’ve specified as fields; for example:
- Titles
- A few blocks of text content
- Perhaps some blocks of predefined image locations
- PDF files that need embedding
Where these fields vary significantly between pages.
The layout, and what fields these pages require would be specified by the developer, so there’s no need to dynamically generate much for this.
The ‘best’ idea I’ve had so far is to serialise these blocks of content once they’ve been edited by the user and store them in a ‘Pages’ table/model in my relational database, or just throw MongoDB or similar at it.
Conceptually, how would you implement such pages? As mentioned, I’m using Django so any implementation suggestions specific to Django are welcome, but general high-level ideas would be great too.
I would implement a
ContentBlockmodel, which has.kind(header, text, image, pdf) and a.data, which would house the content (if text) or path to an uploaded pdf/image/etc. Presumably then you’d hardcode the pages with the appropriate blocks defined – I’d just use hardcoded slugs, eg,'home-title', 'home-intro', 'about-title', 'about-text', 'about-right-photo', etc.I would suggest not using Django’s admin interface. It’s much more suited to editing homogenous, non-business-logic models. I’d just add an edit view that renders the appropriate form fields for the blocks instead – html editor, file upload, etc. It’s possible to do that in the django admin, but in my experience it’s not worth the trouble – plus, if you do your own edit view, you can have it use the same base templates as the rest of the site, which IMO is a better user experience.