I have a restfull API created with Django and DRF. When I try to filter with OR condition (), it doesn't detect the condition and return all the objects. I want to make it work by a diferent way other than modifying the "get_queryset" method.
I want to find the way to implement some module or backend filter package to implement that filters
CodePudding user response:
This can be realized by using Q
objects, as stated in the docs.
For example, suppose you have a model User
with a CharField
type
:
User.objects.filter(
Q(type="admin") | Q(type="moderator")
)
would return all User
objects where type
is either admin
or moderator
.