我想在Django
中创建这样的查询SQLselect auth_group.name auth_user.username
from auth_group, auth_user, auth_user_groups
where auth_user.id = auth_user_groups.id AND auth_group.id = auth_group.id AND auth_group.name = "Operator";
表:
auth_user -> id, username
auth_group -> id, name
auth_user_groups -> id, user_id, group_id
我尝试在django中查询
p = User.objects.all().prefetch_related('groups').get(groups='Operator')
但错误ValueError: invalid literal for int() with base 10: 'Operator'
答案 0 :(得分:2)
更改
get(groups='Operator')
要
get(groups__name='Operator')
你可能会得到几个结果,所以你可能应该这样做:
filter(groups__name='Operator')