On 5 Mar 2010, at 05:15 , aditya bhargava wrote: > > Not quite, because 'in' does exact matching, and I'm looking for the inexact > matching that 'contains' provides. Here's one way to simulate a > 'contains_any' filter: > > t = ["acrylic","watercolors"] # my list of tags > > q = Q(tags__name__contains=t[0]) > for i in range(1,len(t)): > q = q | Q(tags__name__contains=t[i]) > > o = Image.objects.filter(q) # o is the result of the contains_any filter > > > This works fine, but here is the ideal way I'm hoping to write the same > thing: > o = Image.objects.filter(tags__name__contains_any=t) > > > But I'm not sure how to go about adding that new filter.
Are you using django-tagging? It probably provides convenience methods for that kind of "I want the boolean result of the interesection between these two sets" filter. You might also want to check the googles using "intersect" or "intersection" as a keyword, to get stuff like http://stackoverflow.com/questions/108193/union-and-intersect-in-django -- 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.