What is simplest way join __contains and __in?

廉价感情. 提交于 2019-12-02 01:15:02

Here you go:

filter = Q()
for t in tag_tuple: 
   filter = filter | Q(data__contains=t)
return text.objects.filter(filter)

A couple of tips:

  • You should be naming your model classes with a capital (i.e. Text, not text)
  • You may want __icontains instead if you're not worried about the case

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:

def contains_one_of(tags, text):
    text = text.split()   # tags should match complete words, not partial words
    return any(t in text for t in tags)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!