[Django]-Django ORM query with exclude not working properly

5👍

Django by default join multiple conditions with AND operator. Your query will only exclude rows with product__sale_price=0 AND field_value='' AND field_value__isnull=False. If you want OR operator between your conditions, you have to use Q.

from django.db.models import Q


...exclude(Q(product__sale_price=0) | Q(field_value='') | Q(field_value__isnull=False))

Leave a comment