Tuesday, August 4, 2015

Re: Accessing a field's verbose_name

On 5/08/2015 12:53 AM, Déborah Leder wrote:
> Thanks for your answer, Mike.
>
> However, I have just tried it and it doesn't seem to work for me either...
>
> Your code :
> |
> self.__class__()._meta.get_field('{0}'.format(field_name)).verbose_name
> |
> gives the exact same result as
> |
> self._meta.get_field(field_name).verbose_name

Well that's a clue. The problem must be elsewhere. I think that API was
implemented in Django 1.7 because it works for me in 1.7

field_name is a string identical with the field name in the model. And
self must be an instance of the model with the field.

https://docs.djangoproject.com/en/1.8/ref/models/meta/#django.db.models.options.Options.get_field

> |
>
> --
> 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+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/6dff456a-6327-4b7c-a78c-47f36872b0d5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6dff456a-6327-4b7c-a78c-47f36872b0d5%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+unsubscribe@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/55C14E20.4070309%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment