Я пытаюсь увеличить значение переменной "if" в шаблоне Django, я уже попробовал все предложения на этом сайте, но ни одно из них не решило мою проблему.
есть views.py
class IndexView(generic.ListView):
template_name = 'home/index.html'
context_object_name = 'problemes'
def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
context_data['problemes'] = Probleme.objects.all()
context_data['commentaires'] = Commentaire.objects.all()
return context_data
def get_queryset(self):
result_list = self.get_context_data
return result_list
и index.html
....
{% for problem in problemes %}
{% with number_comment= 0%}
{% for comment in commentaires %}
{% if comment.probleme.id == problem.id %}
{% number_comment ++ %}
{% endif %}
{% endfor %}
<tr data-status="pagado">
<td>
<div class="votes">
<div class="mini-counts"><span title="74 votes">74</span></div>
<div>votes</div>
</div>
</td>
<td>
<div class="status answered-accepted" title="one of the answers was accepted as the correct answer">
<div class="mini-counts"><span title="2 answers">{{ number_comment }}</span></div>
<div>answers</div>
</div>
{% endwith %}
....