How access verbose_name of a instance in template?

23 views
Skip to first unread message

Neto

unread,
Nov 5, 2014, 10:29:57 PM11/5/14
to django...@googlegroups.com
How access verbose_name of a instance in template?

I have:
car = Car.objects.get(pk=1)

In my template:

{{ car.color.??? }} {{ car.color }}

I wanna print the verbose_name, i want to it:

Color: red

Mike Dewhirst

unread,
Nov 6, 2014, 12:23:59 AM11/6/14
to django...@googlegroups.com
On 6/11/2014 2:29 PM, Neto wrote:
> How access verbose_name of a instance in template?
>
> I have:
> car = Car.objects.get(pk=1)
>

Try this in a script somewhere to see if it returns the verbose name

def get_verbose_name(obj, field):
return
obj.__class__()._meta.get_field_by_name('{0}'.format(field))[0].verbose_name

... and if so, you should be able to pass it into the template along
with other items

> In my template:
>
> {{ car.color.??? }} {{ car.color }}
>
> I wanna print the verbose_name, i want to it:
>
> Color: red
>
> --
> 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...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@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/1eaa4aba-1fe0-49b4-a397-381047b4c72a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/1eaa4aba-1fe0-49b4-a397-381047b4c72a%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages