In my template, I want to get a count of all answers for a question where the Answer.Value = "YES"
I have two models:
class Question(models.Model):
question = models.CharField(max_length=100)
class Answer(models.Model):
question = models.ForeignKey(Question)
value = models.CharField(max_length=3)
My View:
def questn(request, question_id):
qobj = Question.objects.select_related().get(id="1")
return render(request, 'base.html', {'qobj': qobj})
My Template (base.html):
{{ qobj.answer_set.count }} //returns total count of all answers
{{ qobj.answer_set.filter(value="Yes").count }} //breaks my page...
What is the proper way to get a count of all "Yes" answers for this question?