【问题标题】:Conditional filtering on Count - Django计数条件过滤 - Django
【发布时间】:2017-07-25 18:32:38
【问题描述】:

我想计算有问题的所有错误选择的数量。

我有很多选择的查询:

questions.annotate(choices_count=Count('choices'))

现在,当我只想将不正确的选择过滤到 Count 函数中时,它会返回:

无法将关键字“选择”解析为字段。

questions.annotate(choices_count=Count(Case(When(choice__correct=False,then=1))))

你知道怎么做吗?

【问题讨论】:

    标签: python django django-1.10 django-aggregation


    【解决方案1】:

    在检查它为 False 时,您可能正在写 'choice' 而不是 'choices'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-12
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      相关资源
      最近更新 更多