Django: How to filter for keyword in multiple fields on a model?

Viewed 3180

I have Article model with title and body fields. I'm building a search functionality and need to filter for articles that have keywords either in title or body fields.

I have two Articles. One has "candy" in the title and the other has "candy" in the body. So my result filter should have both articles. I'm trying below query but it's bringing me the first article only

Article.objects.filter(title__icontains='candy').filter(body__icontains='candy')

Thx

1 Answers
Related