Django:排除额外用户

时间:2017-10-27 22:16:42

标签: python django

这是我的查询,

users = User.objects.all() # contains all users

extra_users = Models.objects.filter(user=request.user) # contains few users related to request.user through ManyToMany relationship

Hoe可以从用户中排除extra_users吗?

2 个答案:

答案 0 :(得分:0)

尝试:

 extra_users = Models.objects.filter(user=request.user) 
 users = Users.objects.exclude(pk__in=extra_users)

答案 1 :(得分:0)

Users.objects.all().exclude(user=request.user)