Hi Jordan,

On 03/29/2011 11:40 AM, Jordan MacDonald wrote:
> 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 agree with you that there are cases where single-table inheritance is
the nicest model. We don't have it in Django because multi-table
inheritance covers a wider array of use cases with a cleaner database
schema, and allows you to e.g. have required fields on subclasses
enforced by your database schema, which is not possible with STI.

I'm not sure I'd want to have yet another variety of inheritance as a
first-class feature of the Django ORM; the array of existing options
with MTI, abstract inheritance, and proxy models is quite confusing
enough to new users!

I do, however, think an STI implementation for the Django ORM would be a
great candidate for an external utility app (if someone hasn't done it
already). I _think_ it'd be possible to do it without any modifications
to Django itself (although it would probably require poking at some
internal undocumented APIs), and might see significant uptake.

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to