Django:从所有用户中排除用户列表 [英] Django: exclude User list from all Users

查看:100
本文介绍了Django:从所有用户中排除用户列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Django,目前正在研究模型中的方法。我的问题如下:如何从用户实例中排除用户列表?使用此方法:

I just started working with Django, at the moment I am working on a method in a model. My question is as follows: How can I exclude a list of users from user instances? With this method:

def get_other_users(self):
    all = User.objects.all()
    return User.objects.exclude(self.get_shift_users())

我得到错误:AttributeError: 'User'对象没有属性'split'

I get the error: AttributeError: 'User' object has no attribute 'split'

get_shift_users的代码:

Code for get_shift_users:

@property
def get_shift_users(self):
    return User.objects.filter(assign__shift=self)


推荐答案

您应该能够通过编写对称查询来实现它,例如:

You should be able to implement it by writing a symmetrical query, like:

def get_other_users(self):
    return User.objects.exclude(assign__shift=self)

这篇关于Django:从所有用户中排除用户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆