Hi Jordan,

On Tue, Mar 29, 2011 at 08:40:28AM -0700, Jordan MacDonald wrote:
> I'm sure this subject has been beaten to death, but I haven't found an
> answer to a simple scenario and I'm wondering why this hasn't been
> addressed before.
> 
> I have three models, structured like so:
> 
> Document
> -Presentation
> -Spreadsheet
> 
> Document is never instantiated on its own; a prime candidate for an
> abstract base class. However, there are times where I want to list/
> search across all documents, and I'd like to be able to write
> Document.objects.all(). I'd then like to be able to iterate over this
> enumerable and have each object cast to its proper class.
> 
> This is something accomplished with single table inheritance in Rails;
> why don't we have the equivalent in Django?
> 
> I know I could just use the Document class and have a type field, but
> then I have to do all of the type checking legwork manually. I was
> hoping Django would handle normalizing/denormalizing as part of the
> ORM. In essence, creating its own type field automatically in the back-
> end and casting each object to the appropriate class based on the
> string value in this field.
> 
> Does anyone know why this isn't available? Is there an equally
> efficient method of modeling this approach of which I am unaware?

I haven't used it, but maybe you should look into django_polymorphic:

http://bserve.webhop.org/django_polymorphic/

Thanks,
Forest
-- 
Forest Bond
http://www.alittletooquiet.net
http://www.pytagsfs.org

Attachment: signature.asc
Description: Digital signature

Reply via email to