I have a problem using the '|default' in django templates.
If I do this (it works):
<tr>
<td>{% trans 'NAMEOFTHEFIELD' %}:</td>
<td>{{ object.nameofthefield|default:"Not informed" }}</td>
</tr>
But I have many many fields so I do:
{% for name, value in object.get_fields %}
{% if value %}
<tr>
<td>{% trans name %}:</td>
<td>{{ value|default:"Not informed" }}</td>
</tr>
{% endif %}
{% endfor %}
In this case, the default value is not working, and it shows "None" instead of "Not informed" in the template.
Do you know an easy way to fix it?
I guess you are converting to str
in get_fields
method of model. If that is not true, please post your get_fields
method.
^. - StaticX 2012-04-04 22:46