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

后端 未结 6 719
陌清茗
陌清茗 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 23:02

    If you want to iterate on all the fields you need to get the field:

    for f in BotUser._meta.get_fields():
        if hasattr(f, 'verbose_name'):
            print(f.verbose_name)
    

提交回复
热议问题