首页 > 解决方案 > Django 2.1 - 'WhereNode' 对象没有属性 'output_field' 错误

问题描述

我正在尝试过滤 ViewSet 中的一些注释,如下所示:

queryset = Confirmation.objects.values('prediction__specimen_id').annotate(
    sample_id=F('target_prediction__specimen_id'),
    num_selected=Count('selected', filter=Q(selected=True)),
    num_validated=Count('validated', filter=Q(validated=True)),
    num_has_standard=Count('has_standard', filter=Q(has_standard=True)))

但是,我收到以下错误:

'WhereNode' object has no attribute 'output_field'

根据所有指南,我的语法似乎是正确的。我正在运行 Django 2.1。知道发生了什么吗?由于分页,我不能在 Django Rest Framework 中执行此操作吗?

标签: djangodjango-rest-frameworkdjango-2.1django-aggregationdjango-annotate

解决方案


看起来语法确实是问题所在。我的答案已被编辑以包含正确的代码。干杯!


推荐阅读