Make successive calls to filter
, like so:
queryset = Profile.objects.all()
strings = ['keith', 's', 'thompson']
for string in strings:
queryset = queryset.filter(full_name__icontains=string)
Alternatively you can &
together a bunch of Q
objects:
condition = Q(full_name__icontains=s[0])
for string in strings[1:]:
condition &= Q(full_name__icontains=string)
queryset = Profile.objects.filter(condition)
A more cryptic way of writing this, avoiding the explicit loop:
import operator
# ...
condition = reduce(operator.and_, [Q(full_name__icontains=s) for s in strings])
queryset = Profile.objects.filter(condition)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…