Is it possible to compare two variables from a view in Django?

0

Well, I want to compare two variables coming from a view in Django. I'm doing a for and iterating and comparing a value of type CharField (student.matricula) with another CharField (frequency.matricula)! I wondered if you could do that. My result always falls on the else!

<table>
<tr>
    <td>Turma</td>
    <td>Matrícula</td>
    <td>Nome</td>
    <td>Faltas</td>
    <td>Data com hora</td>
</tr>
{% for aluno in alunos_tsi %}
<tr>
    <td>TSI</td>
    <td>{{ aluno.matricula }}</td>
    <td>{{ aluno.nome }}</td>
        {% for frequencia in frequencias %}
            {% if frequencia.matricula == aluno.matricula %}
                <td>{{ frequencia.faltas }}</td>
                <td>{{ frequencia.data_com_hora }}</td>
            {% else %}
                <td>0</td>
                <td>Nenhuma frequência registrada</td>
            {% endif %}
        {% endfor %}
    </td>
</tr>
{% endfor %}
</table>
    
asked by anonymous 06.02.2017 / 15:13

2 answers

1

According to the documentation is possible. I suggest debugging the code to see if the condition is being met.

    
07.02.2017 / 11:19
1

Try using the following comparison:

{% ifequal frequencia.matricula|stringformat:"s" aluno.matricula %}
...
{% endifequal %}

or maybe this:

{% ifequal frequencia.matricula|stringformat:"s" aluno.matricula|stringformat:"s" %}

...
{% endifequal %}

Retired from this post

    
06.02.2017 / 19:58