views:

27

answers:

2

Hi all,

I have a base class A . Two derived classes B , C. Now I have a global class witch contains a many-to-many relation to object A.

Class D:
    aObjects : ManyToMany("A")

how could know the real object the filter query return in object D. I mean : d.objects.get(id=5) now d has n objects of class A, but they are a mix of A,B or C. How can get only those of type B in the query.

Thanks in advance.

A: 

Will this works for you

filter(lambda x: isinstance(x, B), d.objects.get(id=5))

Satoru.Logic
A: 

There's no way to do this automatically. The documentation is quite clear that there's no way to tell from an instance of a base class whether or not it should 'actually' be an instance of a derived class.

The only thing to do is to define a field on the base class that shows what derived type it is, and set this automatically in the the save() method of the various derived classes. Then you can filter on the value of this field.

Daniel Roseman