My model
class TestModel(models.Model) field1 = models.IntegerField() field2 = models.IntegerField() field3 = models.IntegerField() field4 = models.IntegerField() field5 = models.IntegerField()
I need a simple set of queries that applies one condition to all five fields of the model, without writing down each combination of fields and filtering them.
For example, I want to apply a None check condition to two or more fields
TestModel.objects.filter(two_or_more_fields=None)
I do not want to write every possible combination of 5 fields to find a set of queries with any two or more fields like None. In other words, is there a better way to achieve this than:
from django.db.models import Q TestModel.objects.filter(
I think there must be a better and easier way for this.
source share