views:

67

answers:

2

I've worked on multiple sites recently with similar content types but haven't gotten the design I'm looking to achieve.

I have multiple types of content article, interview, video, gallery, blog, etc. All of these models have very similar properties (title, slug, body, pub_date, etc). And since I'm using django and the admin, almost all the admin setting are identical as well. Most will only have one or two additional fields (ie. filename for video, author for blog).

Currents options are

  1. Using single model "Post/Article" and then just have a type_of_content field. This gives me a single model which makes searches easier and faster and its easy to maintain one model. Managers could be used to pull certain types of content.

  2. Have models 'Video, Interview, Audio' subclass a model called "Post/Article". Gains flexibility of working with different models without all the redundacy. Lots of joins though and all the admin code is still duplicated.

  3. Be very redundant and create a separate model for each type of content even though they share the majority of fields. More stuff to maintain, not DRY at all but highest level of flexibility.

Any insight from someone with more experience would be great.

Thank you.

+1  A: 

I don't have that much experience with Django, but it sounds like what you want to do is subclass off of an Abstract Base Class. This avoids creating a table for the abstract parent class, so you get the advantage of your option #2 without the need for joins.

Jeff Bradberry
I used Abstract Base Classes to solve a similar problem. It is a nice solution. I was able to define a custom manager and save method on the base class and use them with sub-classes. It saved a lot of redundant code
Wade
A: 

That is exactly what I wanted. I knew about Multi-table inheritance and Proxy models but wasnt familiar with abstract base classes. Thanks a ton!