from django.db.models import Q
books = Book.objects.filter(Q(title__icontains=key) |
Q(author__icontains=key) |
Q(translators__icontains=key) |
Q(tags__name__icontains=key)
).order_by('-avg_mark')
查询出来的结果会有重复的
使用distinct
做去重处理,代码如下:
books = Book.objects.filter(Q(title__icontains=key) |
Q(author__icontains=key) |
Q(translators__icontains=key) |
Q(tags__name__icontains=key)
).distinct().order_by('-avg_mark')