from django.contrib.auth.models import User
...
resolvers = User.objects.filter(groups__name = 'resolver')
above code is to filter user belongs to group resolver, in this I need to retrieve users those belongs to admin group as well.
I tried
resolvers = User.objects.filter(groups__name = 'resolver' or 'admin')
resolvers = User.objects.filter(groups__name = ('resolver','admin'))
both are failing, please help.
In this, first, pass your dataframe object to the filter function, then in the condition parameter write the column name in which you want to filter multiple values then put the %in% operator, and then pass a vector containing all the string values which you want in the result.
You can use __in
:
resolvers = User.objects.filter(groups__name__in = ('resolver','admin'))
or Q object
to implement OR
condition:
from django.db.models import Q
resolvers = User.objects.filter(Q(groups__name='resolver')| Q(groups__name='admin'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With