models:
completed = models.BooleanField(_('Completed'))
template:
{% if object.completed %}
<strong>{{ object.completed }}</strong>
{% endif %}
outputs:
<strong>True</strong>
what I need:
<strong>Completed</strong>
Also, check out yesno
template filter. Usage:
<strong>{{ object.completed|yesno:"Completed,Uncomplited" }}</strong>
or:
<strong>{{ object.completed|yesno:"Completed," }}</strong>
On other hand, you can always make your own template filter. For example, the next one returns a verbose_name
of specified field:
foo_tags.py:
@register.filter()
def get_field_name(object, field):
verbose_name = object._meta.get_field(field).verbose_name
return verbose_name
template.html:
{% if object.completed %}
<strong>{{ object|get_field_name:'completed' }}</strong>
{% endif %}
{% if object.completed %}<strong>Completed</strong>{% endif %}
You can try to add label property to form field:
completed = forms.BooleanField(label=mark_safe('<strong>Completed</strong>'))
When you will use {{ form.completed.label }}
you will have <label><strong>Completed</strong></label>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With