Search code examples
pythondjangodjango-templatesjinja2

django janja compare database value


I have some data store in the database In boolean. I want to check if the value is True pick the value and perform some action on it.

product: "{{DB_report_query.product.name}}"
{% if DB_report_query.product.summary  == True %}
{{DB_report_query.summary}}
{% endif %}

But this does not work.


Solution

  • If it is a BooleanField then simply use the following:

    {% if DB_report_query.product.summary %}
        {{DB_report_query.summary}}
    {% endif %}