What is simplest way join __contains and __in?

前端 未结 2 1044
一个人的身影
一个人的身影 2021-01-23 03:09

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.

2条回答
  •  旧巷少年郎
    2021-01-23 04:07

    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)
    

提交回复
热议问题