Driving to work this morning I was thinking of how I should have had a look at the generated SQL statement (which I can't do now).
I think you are right, it's the only way the exclusion could have happened. Would you have an idea of how to prevent this, preferrably without having to write the SQL statement myself? Thanks, Mathieu On Aug 3, 12:54 am, Nowell <[EMAIL PROTECTED]> wrote: > I believe that this is due to the fact that the last Q is performing > an INNER JOIN on the Authors table, and therefore is excluding all > records that do not have an entry in your (what I assume is a) > ManyToManyField/ForeignKey. > > On Aug 2, 5:37 pm, LaundroMat <[EMAIL PROTECTED]> wrote: > > > Hi, > > > Suppose I have defined the models from the django documentation > > (http://www.djangoproject.com/documentation/db-api/). > > > I'm performing a search the entries model, and I want to look through > > all of its fields: > > > from django.db.models import Q > > query = > > 'querystring' # > > User supplied querystring, eg "Lawrence" > > lookup = Q(headline__icontains = querystring) | \ > > Q(body_text__icontains = querystring) | \ > > Q(authors__name__icontains = querystring) > > > p = Prediction.objects.filter(lookup).distinct() > > > The models I have built are more complex than the above, but the gist > > is the same. For one reason or another, I get more results when I > > leave out the last Q object (the one looking through the authors' > > names) than when I leave it in. This shouldn't be happening, as all Q > > objects are being OR'ed. > > > I hope I've given enough information for you to try and simulate my > > problem, and perchance find a solution for it. Many thanks in advance > > already. > > > Mathieu --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---