连接 __contains 和 __in 最简单的方法是什么?
我正在做标签搜索功能,用户可以观察很多标签,我将所有标签都放在一个元组中,现在我想找到包含列表中至少一个标签的所有文本。
符号:text__contains__in=('asd','dsa')
我唯一的想法是做循环,例如:
q = text.objects.all()
for t in tag_tuple:
q.filter(data__contains=t)
例如: 输入标签元组,('car', 'cat', 'cinema')
输出包含该元组中至少一个单词的所有消息,因此 My cat is in the car
,cat is not allowed in thecinema
,i will Drive my开车去电影院
感谢您的帮助!
I am doing tag search function, user could observe a lot of tags, I get it all in one tuple, and now I would like to find all text which include at least one tag from the list.
Symbolic: text__contains__in=('asd','dsa')
My only idea is do loop e.g.:
q = text.objects.all()
for t in tag_tuple:
q.filter(data__contains=t)
For example:
input tuple of tags, ('car', 'cat', 'cinema')
output all messages what contains at least one word from that tuple, so My cat is in the car
, cat is not allowed in the cinema
, i will drive my car to the cinema
Thanks for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
给你:
一些提示:
Text
,而不是text
)__icontains
相反,如果你不担心这个案子Here you go:
A couple of tips:
Text
, nottext
)__icontains
instead if you're not worried about the case我不了解 Django,所以我不知道如何应用这个过滤器,但似乎你想要一个像这样的函数:
I don't know Django, so I have no idea how to apply this filter, but it seems you want a function like this one: