在我的模板中,我想计算 Answer.Value = "YES" 的问题的所有答案
我有两个模型:
class Question(models.Model):
question = models.CharField(max_length=100)
class Answer(models.Model):
question = models.ForeignKey(Question)
value = models.CharField(max_length=3)
我的观点:
def questn(request, question_id):
qobj = Question.objects.select_related().get(id="1")
return render(request, 'base.html', {'qobj': qobj})
我的模板(base.html):
{{ qobj.answer_set.count }} //returns total count of all answers
{{ qobj.answer_set.filter(value="Yes").count }} //breaks my page...
计算这个问题的所有“是”答案的正确方法是什么?