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. Aditya On Thu, Mar 4, 2010 at 3:52 PM, Peter Herndon <tphern...@gmail.com> wrote: > On Mar 4, 2010, at 2:56 PM, aditya wrote: > > > I would like to add a new filter for models to my django build that > > can be used as follows: > > > > tags = ['tag1','tag2','tag3'....'tagn'] > > i = Image.objects.filter(tags__contains_any=tags) > > > > > > Essentially, instead of passing a string, I pass a list and get a set > > of valid objects that match *any* of the items in the list. I'm a loss > > for where to look for the relevant code, though....I'm trying to find > > where the 'contains' filter has been implemented, so that I can take a > > look at how its written. Currently I'm looking at db.models.query and > > db.models.query_utils. Where should I be looking? > > > Hi Aditya, > > Won't the "in" filter do exactly what you need? > > http://docs.djangoproject.com/en/1.1/ref/models/querysets/#in > > ---Peter > -- 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.