[Django]-How to use "OR" using Django's model filter system?

83👍

You can use Q objects to do what you want, by bitwise OR-ing them together:

from django.db.models import Q
Publisher.objects.filter(Q(name__contains="press") | Q(country__contains="U.S.A"))

1👍

Without Q(), you can also run OR operater as shown below:

Publisher.objects.filter(name__contains="press") | \
Publisher.objects.filter(country__contains="U.S.A")

Leave a comment