Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

The basics of creating a tumblelog with Django (via) Ryan Berg suggests having a StreamItem model that links uses a GenericForeignKey to link to other content types, then using signals to cause a StreamItem to be created for every other model type. I should switch to doing that on this blog: at the moment I have to query three separate tables to build the tumblelog part which results in messy code for ordering and pagination.

3 comments

  1. Couldn't you use an abstract base class or multi table inheritance (implicit one to one mappings) from the new model inheritance hotness to do the same?

    James Wheare - 25th June 2008 18:46 - #

  2. James, someone just asked the same question at the original post. Model inheritance wasn't around when I began writing this code, but I can certainly see it being used successfully for a tumblelog.

    My question, since I'm not that familiar with model inheritance yet, is how you can use that inheritance with models you don't have the ability (or shouldn't) modify, like from a contrib app or maybe a third party library?

    Ryan Berg - 26th June 2008 04:26 - #

  3. I'm not hugely familiar with it myself, but it sounds like multi table inheritance would handle that fine. The parent class has it's own table, separate from child classes, and the two are related with an automatic OneToOne field.

    The other type of model inheritance involves abstract classes that don't correspond to tables and serve only to be extended.

    The whole point of inheritance is you don't modify the parent, you extend it with extra functionality.

    James Wheare - 26th June 2008 19:06 - #

Sign in with OpenID

Auto-HTML: Line breaks are preserved; URLs will be converted in to links.

Manual XHTML: Enter your own, valid XHTML. Allowed tags are a, p, blockquote, ul, ol, li, dl, dt, dd, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, sub, sup, br, pre

A django site