I have a django app where I iteratively do filters in a loop. Here is a simplified example:
class Decision(models.Model):
recommendation = models.TextField()
class Condition(models.Model):
dec = models.ForeignKey(Decision, related_name='condition')
temperature = models.PositiveInteger()
pressure = models.PositiveInteger()
Decision.objects.filter(condition__temperature=22, condition__pressure=123 ).filter(condition__temperature=30, condition__pressure=144).values_list('id',flat=True)
As you can see, the conditions are ANDed. Is there a more efficient way to do this query?
Here is another approach but it is not giving me any result:
Decision.objects.filter(Q(condition__temperature=22, condition__pressure=123 ) &\
Q(condition__temperature=30, condition__pressure=144)).values_list('id',flat=True)