from django.contrib.auth.models import User
...
resolvers = User.objects.filter(groups__name = 'resolver')
上面的代码是过滤用户属于组解析器,在此我需要检索那些属于管理员组的用户。
我试过
resolvers = User.objects.filter(groups__name = 'resolver' or 'admin')
resolvers = User.objects.filter(groups__name = ('resolver','admin'))
两者都失败了,请帮忙。
答案 0 :(得分:2)
您可以使用__in
:
resolvers = User.objects.filter(groups__name__in = ('resolver','admin'))
或Q object
实施OR
条件:
from django.db.models import Q
resolvers = User.objects.filter(Q(groups__name='resolver')| Q(groups__name='admin'))