This works:

 >>> from django.db.models import Q
 >>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
 >>> Books.objects.filter(qset)

But what if the list of things I want to search against is a list.
E.g.

 >>> possible_authors = [u"Foo", u"Bar"]

???


I have a solution but it's very ugly and feels "clunky":

 qset = None
 for each in [u"Foo", u"Bar"]:
     if qset is None:
         qset = Q(author__iexact=each)
     else:
         qset = qset | Q(author__iexact=each)


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

Reply via email to