On Jul 25, 7:03 am, "Adam Fast" <[EMAIL PROTECTED]> wrote: > Hello, > > I'm using Multi-Table Inheritance as the basis of a tumblelog - all > the common pieces of data are stored on the base class / table > (StreamItem) > > I'm doing a StreamItem.objects.all() and looping through the items. > But I'm wondering if there's a way to find out which "child" class the > base class item is linked to - for example, one child class is Photo > and another Entry. Can I find out that this particular StreamItem is > a Photo vs an Entry? I have it "rigged" using is_* methods I've > written - basically catch the child classes' DoesNotExist exception > (when doing StreamItem.photo / StreamItem.entry) and return whether it > is one of those items or not - but I don't think this is the smartest > way to go.
Multi-table inheritance creates a reverse relationship with the child: class Parent(models.Model): class ParentChild(Parent): # my object IS this one class ParentOtherChild(Parent): # my object isn't one of these u = Parent.objects.all()[0] u.parentchild # this is the object you want u.parentotherchild # raises ParentOtherChild.DoesNotExist --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---