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

后端 未结 6 726
陌清茗
陌清茗 2021-02-06 22:12

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

6条回答
  •  天涯浪人
    2021-02-06 22:49

    For Django 1.11 and 2.0:

    MyModel._meta.get_field('my_field_name').verbose_name
    

    More info in the Django doc

提交回复
热议问题