How to return field name containing a given value in a django model?

Viewed 220

I have a list of strings I want to search for in my database, and I want my function to return the name of the field that contains the string:

    for word in word_list:
        if word in MyModel.objects.all():
           return ?? 

How do I complete the function so that it accomplishes this?

1 Answers

This way you can pass the list of words and can return all the QuerySet that contains all the words in the word_list

for word in word_list:
    return MyModel.objects.filter(word__icontains = word)
Related