I have a case where I'm trying to OR several conditions together in a
query, and I'm including a query against a field in a foreign key
field.

        queryset = queryset.filter(
            Q(clientid__icontains=filter) |
            Q(description__icontains=filter) |
            Q(icp__name=filter)
            )

here, icp is a foreign key, and we're trying to match it's field
"name".

In some cases, icp is NULL, so there is no corresponding model to
follow, and in those cases, this query always fails to return models
that it otherwise would.

For example, in matching a description substring, 4 objects would be
returned that have that substring, but if I OR with the final part of
this where the icp.name is checked, and 3 of the 4 returned have NULL
icps, then only 1 model is returned.

I find this very non-intuitive, and I'm wondering if this is
intentional. It is an OR condition, afterall, so I don't see why a non-
null icp should be required here.

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

Reply via email to