Re: And-ing together searches on a ManyToMany field.

2006-07-21 Thread Neilen Marais
On Fri, 21 Jul 2006 09:50:15 +1000, Malcolm Tredinnick wrote: > Because of the way QuerySets are constructed, there's no easy way to > tell when a user is walking into this case. The current behaviour may > reasonably be considered a semi-bug, however it's unavoidable at the > moment since we

Re: And-ing together searches on a ManyToMany field.

2006-07-20 Thread Malcolm Tredinnick
On Thu, 2006-07-20 at 22:31 +0200, Neilen Marais wrote: > Malcolm, > > On Thu, 20 Jul 2006 16:56:22 +1000, Malcolm Tredinnick wrote: [...] > > > > Here's a solution that I prepared earlier (it talks about finding all > > groups containing a subset of people, but it's the same problem): > > > >

Re: And-ing together searches on a ManyToMany field.

2006-07-20 Thread Neilen Marais
Malcolm, On Thu, 20 Jul 2006 16:56:22 +1000, Malcolm Tredinnick wrote: >> > I think you want to use: >> > >> > Image.objects.filter(tags__id__in=[1,2]).distinct() >> >> Alas, this returns all the images with tag1 OR tag2. I'm looking for >> images with tag1 AND tag2. > > Here's a solution

Re: And-ing together searches on a ManyToMany field.

2006-07-20 Thread Malcolm Tredinnick
On Thu, 2006-07-20 at 08:35 +0200, Neilen Marais wrote: > Matthew, > > Thanks for the info. > > On Thu, 20 Jul 2006 10:05:43 +1000, Matthew Flanagan wrote: > > >> In [73]:Image.objects.filter(tags__id=1).filter(tags__id=2) > >> Out[73]:[] > >> > > > > I think you want to use: > > > >

Re: And-ing together searches on a ManyToMany field.

2006-07-20 Thread Neilen Marais
Matthew, Thanks for the info. On Thu, 20 Jul 2006 10:05:43 +1000, Matthew Flanagan wrote: >> In [73]:Image.objects.filter(tags__id=1).filter(tags__id=2) >> Out[73]:[] >> > > I think you want to use: > > Image.objects.filter(tags__id__in=[1,2]).distinct() Alas, this returns all the images

Re: And-ing together searches on a ManyToMany field.

2006-07-19 Thread Matthew Flanagan
On 7/20/06, Neilen Marais <[EMAIL PROTECTED]> wrote: > > Hi > > A photo-app I'm working on has tags on an image defined as a many to many > relationship: > > class Image(models.Model): > filename = models.CharField(maxlength=255) > description = models.TextField() > tags =

And-ing together searches on a ManyToMany field.

2006-07-19 Thread Neilen Marais
Hi A photo-app I'm working on has tags on an image defined as a many to many relationship: class Image(models.Model): filename = models.CharField(maxlength=255) description = models.TextField() tags = models.ManyToManyField(Tag) Given several tags: TagA, TagB, ..., I'm trying to