Created
November 13, 2019 13:11
-
-
Save jmorakuebler/6a58d92b9a01ad91a581f7dfd6772b2d to your computer and use it in GitHub Desktop.
Custom django template tag that returns the verbose name of a field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.template import Library | |
register = Library() | |
@register.simple_tag | |
def get_field_verbose_name(instance, field_name): | |
"""Returns the verbose_name of the specified field.""" | |
return instance._meta.get_field(field_name).verbose_name.title() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load get_field_verbose_name %} | |
<!-- Will display the verbose_name and the value of the field --> | |
<p>{% get_field_verbose_name object 'my_field' %}: {{ object.my_field }}</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment