hi Dave

finally, i have tried what you suggested. indeed, this is what is described
here<http://www.djangoproject.com/documentation/model-api/#multi-table-inheritance>.
and it works!

thanks a lot!
cheers
André


On Tue, Jul 8, 2008 at 3:13 PM, Chester <[EMAIL PROTECTED]> wrote:

>
> André,
> I'm assuming that you are using the Trunk version of Django because
> subclassing isn't supported in previous versions.
>
> Assuming that.
>
> You can either have Item be an Abstract class which does not act like
> a table but just a parent class containing common items. (this is not
> what you are trying...)
>
> Or
>
> Each sub class is a seperate model from Item (assuming this is what
> you want).   From the documentation you should be able to do the
> following:
>
> items = Item.objects.all()
> for item in items:
>  try:
>    x = Item.task
>    type = "Task"
>  except:
>    try:
>       x = Item.event
>       type = "Event"
>    except:
>       type = "Item"
>  Do something pertaining to the item type....
>
>
> I haven't tried this but according to the docs it should work.... You
> should also fill in the correct exception.  I just don't know what it
> is.
>
> Hope it helps.
>
> Dave.
>
>
>
>
>
>
> On Jul 8, 2:12 am, "Andre Meyer" <[EMAIL PROTECTED]> wrote:
> > hi all
> >
> > is it possible to determine the subclass of a model instance?
> >
> > what i mean is this:
> > if you have a (n abstract) model class and two subclasses, like
> >
> > class Item(models.Model):
> >     pass
> >
> > class Task(Item):
> >     pass
> >
> > class Event(Item):
> >     pass
> >
> > and you retrieve
> >
> > items = Item.objects.all()
> >
> > how can you know whether the items are either tasks or events?
> >
> > items[0].__class__ returns just <class 'proj.app.models.Item'>.
> >
> > thanks for sharing your insights
> > regards
> > André
> >
>

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

Reply via email to