Django - 如何在 'NOT IN' 中指定 'limit_choices_to' ?

标签 django django-models django-admin

如何在“limit_choices_to”中指定“NOT IN”?我只想获取所有客户详细信息,除非他们处于一种特定状态。

customer = models.ForeignKey(Customer, limit_choices_to={'status__in': ['active']}) 

最佳答案

只是使用 Q 对象而不是字典。

limit_choices_to = ~models.Q(status__in = ['xxxxxx']))

关于Django - 如何在 'NOT IN' 中指定 'limit_choices_to' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4268672/

相关文章:

javascript - 使用 ws 的 Django channel ://but fails to handshake with wss://

Django,用名字和姓氏注册用户?

python - 使用 Django 模型的促销代码

python - 测试 Django 中外键的重复条目 '1'

Django,如何将变量传递给平面页面?

python - 如何过滤django中的日期时间字段

django - 如何在 POST 请求后返回重定向到 Django 中的上一页

来自相关模型的 django 管理显示字段

python - sys.path 不包含 PYTHONPATH (必须输入完整路径才能运行 django-admin startproject)