Single Table Inheritance

2011-03-29 Thread Jordan MacDonald
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?

-- 
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.



Re: Single Table Inheritance

2011-03-29 Thread Jordan MacDonald
Cool.

Well, maybe I can look into how abstract base classes are currently
implemented and see if there's a way to generate query sets for all
derived classes from the parent.

Thanks for the insight!

On Mar 29, 12:40 pm, Carl Meyer  wrote:
> On 03/29/2011 12:40 PM, Jeremy Dunck wrote:
>
> > What about keeping abstract inheritance in this case, but allowing
> > Document.objects.* to work by returning instances of the subclasses.
> > Filtering, etc. would only work based on the Document base class.
>
> > It would mean doing some unions, but would still fit the use case
> > pretty well, I think.
>
> I'd certainly be intrigued to look at a patch that implemented that.
>
> 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.