Django多关键词搜索

1.import Q和operator

from django.db.models import Q
import operator

2.分割关键词
keys = key.split(' ')
condition = reduce(operator.and_, (Q(title__contains=x) for x in keys))

3.用condition作为过滤条件查询
item.objects.filter(condition)