Reputation: 1052
I use the following template tag:
@register.simple_tag
def get_verbose_field_name(instance, field_name):
"""
Returns verbose_name for a field.
"""
return instance._meta.get_field(field_name).verbose_name.title()
Assume I have defined a model field lorem_ipsum
with the field's verbose_name="FOO bar"
.
Then, when I run {% get_verbose_field_name object "lorem_ipsum" %}
in the template in a table's <th>
element, I receive "Foo Bar".
However, I want to keep the verbose name exactly how I defined it—in this example as "FOO bar". How can one disable auto-capitalization of verbose names?
Upvotes: 0
Views: 148
Reputation: 2098
You can use both of the below methods for this purpose:
@register.simple_tag
def get_verbose_field_name(instance, field_name):
"""
Returns verbose_name for a field.
"""
return instance._meta.get_field(field_name).verbose_name
or
@register.simple_tag
def get_verbose_field_name(instance, field_name):
"""
Returns verbose_name for a field.
"""
return instance._meta.get_field_by_name(field_name).verbose_name
Upvotes: 4
Reputation: 410722
Remove the call to title()
:
@register.simple_tag
def get_verbose_field_name(instance, field_name):
"""
Returns verbose_name for a field.
"""
return instance._meta.get_field(field_name).verbose_name
Upvotes: 3