I have a django model and a field representing a users full name. My client wants me to set up a filter to search for a user based on an array of strings where all of them have to be case insensitive contained within the full name.
For example
If a users full_name = "Keith, Thomson S."
And I have a list ['keith','s','thomson']
I want to perform the filter equivalent of
Profile.objects.filter(full_name__icontains='keith',full_name__icontains='s',full_name__icontains='thomson')
The problem is this list can be of dynamic size – so I do not know how to do this.
Anyone have any ideas?
Make successive calls to
filter, like so:Alternatively you can
&together a bunch ofQobjects:A more cryptic way of writing this, avoiding the explicit loop: