Hi,

I need to be able to query an object that has a set of related  
objects - the query is to find which objects contain the same set of  
query objects. For example the main object could be a research paper  
and the related object would be a set of topics that the papers could  
contain.

class Topic(models.Model):
     label = models.CharField(maxlength=255)

class Paper(models.Model):
        topic = models.ManyToManyField(Topic)

I have tried a few approaches, I thought I could simply chain a  
series of filters or AND some Q objects:

In [28]: p=Paper.objects.filter(topic=t2).filter(topic=t)

In [29]: p
Out[29]: []


In [39]: Paper.objects.filter(Q(topic=t)|Q(topic=t2))
Out[39]: [<Paper: title1>, <Paper: title2>]

In [40]: Paper.objects.filter(Q(topic=t),Q(topic=t2))
Out[40]: []

But these don't work and I end up with an empty query set, but there  
is  a Paper object with both a t and t2 object.

Thanks,
jms.

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