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

Asked

Viewed 152 times

0

Well, I want to compare two variables coming from a view on Django. I’m doing one for and iterating and comparing a Charfield value (student.matricula) with another Charfield (frequencia.matricula)! I wanted to know if it is possible to do this. My result always falls in 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>
  • Here we do not write "solved" in the question. If you have an answer that really helped you, mark it as accepted. If you came to the solution on your own, put in the solution as an answer. So content is more organized and easier to find in the future by other people with similar problems.

2 answers

1


  • Thanks for your attention. I already solved the problem, hug.

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 %}

Taken from that post

Browser other questions tagged

You are not signed in. Login or sign up in order to post.