On Mon, Feb 9, 2009 at 9:11 PM, Malcolm Tredinnick <malc...@pointy-stick.com
> wrote:

>
> On Sat, 2009-02-07 at 12:40 -0800, seanbrant wrote:
> > Im have troubling figuring about a good solution for blog posts. I
> > have created a ABC called Entry which Post, Link, Photo, Quote
> > inherit.
>
> It would help others to define a few terms here before leaping into the
> acronyms: ABC = "abstract base class", MTI = "multi-table inheritance",
> I'm guessing.
>
> >
> > I first tired it with MTI and set Entry.objects.all() as the queryset
> > attribute. This will pass the list of Entry's to the template which I
> > can iterate over. However I would like to style each type of Entry
> > object a little different. Is there a way to know which type of Entry
> > you are dealing with.
>
> Yes, by adding a field called "child_type" or something similar and
> noting the content type of the most derived child, for example.
>
> > Then I tried ABC with the same models. Obviously including abstract
> > True to the Base Entry class. With this approach I have know idea  how
> > to get a query set for all of these objects.
>
> You can't. They different types aren't related to each other. You need
> to make "N" querysets and write your own version of the generic view
> (remember, generic views are just an aid -- they don't fit all
> requirements and not using them is always an option).
>
> > This seems like a fairly common use-case,
>
> Which is why it's been answered a number of times in the past. :-)
>
> Malcolm
>
>
> >
>
If you choose to work with MTI I've worked up a bit of code that will
automatically denormalize which subclass on object is, and load up the
correct one when something is fetched from the ORM(note that this could turn
a Base.objects.all() query into O(n) queries).  In any event here is the
code: http://dpaste.com/118723/ I plan to write up a proper blog post on it
later at some point.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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

Reply via email to