Milano
Milano

Reputation: 18705

Conditional filtering on Count - Django

I want to count a number of all incorrect choices in question.

I have a query for a number of all choices:

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

Now, when I want to filter incorrect choices only into the Count function, it returns:

Cannot resolve keyword 'choice' into field.

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

Do you know how to do that?

Upvotes: 0

Views: 249

Answers (1)

k_hotspot
k_hotspot

Reputation: 134

Probably you are writing 'choice' instead of 'choices' while checking it to False

Upvotes: 2

Related Questions