On Wed, Feb 25, 2009 at 1:34 PM, Kevin Audleman <kevin.audle...@gmail.com>wrote:
> > What about the following? > > qset = Q(author__in=[u"Foo", u"Bar"]) > > > Kevin > > On Feb 25, 10:03 am, Peter Bengtsson <pete...@gmail.com> wrote: > > 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) > > > Kevin, the way IN works at the SQL level basically means that it will be doing an exact match against each item, which isn't what he wants, he wants an iexact match. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---