Thank you! I was trying to hunt that down but gave up hope and assumed django didn't handle that. Saves me several lines, thanks again
On Apr 12, 3:18 pm, Ian Struble <istru...@gmail.com> wrote: > I think you are looking for the 'in' field lookup: > > http://docs.djangoproject.com/en/dev/ref/models/querysets/#in > > Item.objects.filter(genre__in=some_video.genre.all()) > > On Apr 12, 10:03 am, Nick Serra <nickse...@gmail.com> wrote: > > > > > Hey everyone, thanks for looking. I couldn't think of a good title for > > this one. I have a question on queries on manytomany relations. Here > > is an example: > > > class Item: > > genre = models.ForeignKey(Genre) > > > class Genre: > > name = models.CharField() > > > class Video: > > genre = models.ManyToManyField(Genre) > > > Heres the situation.. I want to do a get() on item and find any items > > where the item.genre is equal to one of the video's genres. A video > > can have many genres. > > > My first thought was Item.objects.get(genre=video.genre.all()), but > > this only works when there is only one genre selected for the video. > > Is there any way to do this without doing an iteration on the videos > > selected genres and testing each case? > > > I feel like i've accomplished this before, but I may just be having an > > off day. Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.