views:

32

answers:

1

Is there a recommended best-practice for storing content that has a complex structure. For example, suppose a typical "article" I am trying to serve may have the following hierarchy:

Header #1
   Subheader #1.a)
      Text content
      Image content
      Text Content
   Subheader #1.b)
      Text Content
      Other complex content type, such as syntax highlighted code block
Header #2
...

I am struggling with how to decompose this into appropriate database structure so that it can be rendered using a template.

I understand how I could use composition to separate the subcomponents of the article into pieces (e.g. Header, Subheader, Content) with each child pointing to its parent. However, I am struggling with how to store directions for putting everything back together at the content level. I suppose you could store an index with each content block that defines order e.g.:

for each header in article
   print header
   for each subheader in header
      print subheader
      for each content block in subheader (ordered by index)
         print content block

Is this an advisable method to use for this problem or is there a much cleaner approach? Any help would be appreciated.

P.S. I suppose this isn't really a Django specific question, but Django is my ultimate means of implementing this.

A: 

Looks like a common approach to this problem is to use markup filters. Examples include Markdown and Textile. In this approach you would store an entire article as one blob in the database and then use the markup filter to convert the raw data (including some primitive layout information) into HTML.

Marcus