Quick reply to myself in case someone is looking through the archives. This seems to be covered in ticket 1801: http://code.djangoproject.com/ticket/1801
It's noted as a 'hard bug'. On 16/01/07, Felix Ingram <[EMAIL PROTECTED]> wrote: > Hello all, > > I've run into a problem when trying to add some simple search > functionality to my app. I've got a model with several M2Ms and I'm > trying to construct some OR queries using Q(). > > Here's a simplified example: > > Model: > > class Article(models.Model): > authors = models.ManyToManyField(User, blank=True, null=True) > pictures = models.ManyToManyField(Picture, blank=True, null=True) > > View: > > def search(request): > if request.POST: > q = Q() > for term in request.POST["searchTerms"].split(): > q = q | Q(authors__name=term) > q = q | Q(pictures__title=term) > results = Article.objects.filter(q) > return render_to_response('search.html', {'results': results}) > > My problem arises when an Article has authors but no pictures (or vice > versa). If this is the case then the join with the Pictures table > fails to produce anything and I get no results. If an Article has a > Picture then results are returned even if the term only matches on > authors__name. > > Is there something I'm missing? > > Any pointers or suggestions welcome. > > Regards, > > Felix > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---