App engine NDB: how to access verbose_name of a property

有些话、适合烂在心里 提交于 2019-12-06 02:13:20

问题


suppose I have this code:

class A(ndb.Model):
    prop = ndb.StringProperty(verbose_name="Something")

m = A()
m.prop = "a string value"

Now of course if I print m.prop, it will output "a string value" while in fact it's a StringProperty instance. So verbose_name can't be accessed the "normal" way, i.e m.prop._verbose_name.
I read the code and found a way to access it: m._properties["prop"]._verbose_name, it works, but it looks hacky o_o.
So tell me, is there another way to do it?
Note: I'm talking about the NDB API, not the old one


回答1:


Use a class attribute: A.prop._verbose_name. Or m.__class__.prop._verbose_name.



来源:https://stackoverflow.com/questions/11166242/app-engine-ndb-how-to-access-verbose-name-of-a-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!