You could write up a simple template tag (or even a template filter) to do
this.

https://docs.djangoproject.com/en/1.8/howto/custom-template-tags/#simple-tags

Something along these lines would probably work:

# templatetags.py
register = template.Library()

@register.simple_tag
def verbose_name_tag(obj, field_name):
    return obj._meta.get_field(field_name).verbose_name

@register.filter
def verbose_name_filter(obj, field_name):
    return obj._meta.get_field(field_name).verbose_name

# in template.html
{% load mytemplatetags %}

{# template tag #}
<span>{% verbose_name_tag p 'name' %}: {{ p.name }}</span>
<span>{% verbose_name_tag p 'birth_date' %}: {{ p.birth_date }}</span>

{# template filter #}
<span>{{ p|verbose_name_filter:'name' }}: {{ p.name }}</span>
<span>{{ p|verbose_name_filter:'birth_date' }}: {{ p.birth_date }}</span>

Untested, although I don't see why it wouldn't work. I have similar tags
built for the verbose_name and verbose_name_plural of the object itself.

You would need to decide whether a tag or filter is more readable, although
I would personally choose a tag this in this case. You may also want to
make the tags a bit more resilient against bad field names, etc.

HTH,

-James


On Mon, Aug 10, 2015 at 9:35 PM, Neto <paulosouzamac...@gmail.com> wrote:

> If is to do that way, I prefer to do manually. I would like to access the
> direct verbose_name the template. Is possible that the "Django developers"
> could do this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b811a0c5-5aed-49b9-9835-3baab66a7ad6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b811a0c5-5aed-49b9-9835-3baab66a7ad6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXEyzhFe%2B1yTGXVkuhZ95G0PnzEvEaNt3Md_vazvk51RA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to