python - 不在 Python 中过滤

标签 python django django-views

我有一个 list

customers=Customers.objects.filter(limit=1)

level1=customers.filter(status=1)

level2=customers.filter(status=2)

我想填充第三个列表,该列表必须包含 customers 但不在 level1level2 中的所有客户的名称/p>

我试过这么多

returned=customers.filter(~level1) 

最佳答案

您可以使用 exclude() :

Customers.objects.exclude(status__in=[1,2])

Customers.objects.filter(whatever=whatever).exclude(status__in=[1,2])

关于python - 不在 Python 中过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17291768/

相关文章:

python - Django 模板中的动态表单字段生成

django - 无法使用Django Haystack和Elasticsearch搜索术语的一部分

Django 在每个页面上添加一个反馈表

java - 使用正则表达式重新格式化代码

python - IPython 中输入编码的奇怪问题

python - Keras:如何在某些层结果之上进行平均/最大运算?

django - '用户' 对象没有属性 'username'

python - 从基于 Django 类的 View 的 form_valid 方法调用特殊(非 HTTP)URL

django-views - Django 1.3 CreateView/ModelForm : unique_together validation with one field excluded from form

python - Augmented Dickey–Fuller 测试中的 BIC 在 Python 中究竟如何工作?