Hi Julien, The "in" filter translates to an SQL in clause, which in turns simulates or functionality like you are experiencing. The type of clause you are looking for is similar to:
where x=1 and x=2 and x=3 What I would try to do (and I'm a newbie with all this too) is dynamically create a bunch of Q objects (http://www.djangoproject.com/ documentation/db-api/#complex-lookups-with-q-objects) I think this may work.... haven't tested it. from django.db.model import Q def make_Q(the_list): q = None for x in the_list: q = q & Q(codes=x) return q The to retrieve the objects: Quote.objects.filter(make_Q(code_pk_list)) Hope that helps, Keith On Jan 20, 8:03 pm, Julien <[EMAIL PROTECTED]> wrote: > Hi all, > > Sorry if this has been asked before, but I could not find help in the > search. > > Here's my code: > > class Code(models.Model): > name = models.CharField(max_length=100) > > class Quote(models.Model): > content = models.CharField(max_length=100) > codes = models.ManyToManyField(Code, null=True, blank=True) > > I want to filter out a model by testing values in a list. If I use > "__in" it seems to do a OR filter: > > quotes = Quote.objects.filter(codes__in = code_pk_list) > > By OR filter I mean that it returns any quote that has a code in the > list... > > Rather I'd like a AND filter, that is something that only returns the > objects that have at least ALL the values given in the list. > > Do you know how to do this? > > Many thanks, > > Julien --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---