Home > Software engineering >  Use or for filter combination
Use or for filter combination

Time:03-07

I have two query like this below,

Both,It works correctly, but I want to use OR for these sentences.

I have ideas to use Q

But it has complex filter.

cls.objects.filter(point1__gt=0).filter(point1__lt=100)

cld.objects.filter(point2__gt=0).filter(point2__lt=100)

Is there any method to use OR for this sentenses?

CodePudding user response:

You can try different ORM methods here, take a glance below:

cls.objects.filter(point1__range=(0, 100))
cld.objects.filter(point2__range=(0, 100))

NOTE that you can do the same with Q function, you said OR above, I think you need AND here.

Links for Django official documentation:
https://docs.djangoproject.com/en/4.0/ref/models/querysets/#range

  • Related