IPr*_*ory 2 django django-orm django-queryset
我正在做标签搜索功能,用户可以观察很多标签,我在一个元组中得到它,现在我想找到包含列表中至少一个标签的所有文本.
符号:text__contains__in=('asd','dsa')
我唯一的想法是做循环,例如:
q = text.objects.all()
for t in tag_tuple:
q.filter(data__contains=t)
Run Code Online (Sandbox Code Playgroud)
例如:标签输入元组,('car', 'cat', 'cinema')
输出的所有消息什么包含从元组至少一个字,所以My cat is in the car,cat is not allowed in the cinema,i will drive my car to the cinema
感谢您的帮助!
干得好:
filter = Q()
for t in tag_tuple:
filter = filter | Q(data__contains=t)
return text.objects.filter(filter)
Run Code Online (Sandbox Code Playgroud)
一些提示:
Text,不是text)__icontains如果你不担心这个案子,你可能会想要| 归档时间: |
|
| 查看次数: |
1224 次 |
| 最近记录: |