Hi,

On 29.10.2007, at 21:58, Kevin wrote:
>
> I'm trying to figure out how to chain filters for a many-to-many
> relation ship that is evaluating to an empty set when it should not. I
> basically have some a test with multiple dimms. I want to find a test
> with both dimm "sizes" 1024 & 2048.
>
> class TestLine(models.Model):
>      #...some test info
>
> class Dimm(models.Model):
>    testline = models.ForeignKey(TestLine)
>    size = models.IntegerField()
>
> models
> .TestLine.objects.filter(dimm__size=1024).filter(dimm__size=2048)
>
> This returns an empty set, but I know there is a test with multiple
> dimm objects and meets this criteria. Is there a limitation that I'm
> missing here? Is there an alternative method to accomplish the intent
> here?
>

You should probably take a look at the Q objects:
http://www.djangoproject.com/documentation/db-api/#complex-lookups-with-q-objects

Something like this might work (untested):

models.TestLine.objects.get( Q(dimm__size=1024) | Q(dimm__size=2048) )

-- 
http://spinlock.ch/blog/



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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