How can I get access to a Django Model field verbose name dynamically?

philgo20 picture philgo20 · Mar 11, 2010 · Viewed 27.2k times · Source

I'd like to have access to one my model field verbose_name.

I can get it by the field indice like this

model._meta._fields()[2].verbose_name

but I need to get it dynamically. Ideally it would be something like this

model._meta._fields()['location_x'].verbose_name

I've looked at a few things but I just can't find it.

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Mar 11, 2010

For Django < 1.10:

model._meta.get_field_by_name('location_x')[0].verbose_name