Reputation: 790
I want to make a query like this:
Mymodel.objects.filter(description__icontains='something' or title__icontains='something')
However using the or
statement does not work. Putting a comma makes it an and
statement. How do I solve this?
Upvotes: 1
Views: 18
Reputation: 477607
You wrap the conditions in Q
objects [Django-doc], and use the bitwise or operator (|
) as an OR:
from django.db.models import Q
Mymodel.objects.filter(
Q(description__icontains='something') |
Q(title__icontains='something')
)
Upvotes: 1