App Engine NDB:如何访问属性的verbose_name [英] App engine NDB: how to access verbose_name of a property

查看:31
本文介绍了App Engine NDB:如何访问属性的verbose_name的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个代码:

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

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

当然,如果我打印 m.prop,它会输出一个字符串值",而实际上它是一个 StringProperty 实例.因此,verbose_name 无法以正常"方式访问,即 m.prop._verbose_name.
我阅读了代码并找到了访问它的方法:m._properties["prop"]._verbose_name,它可以工作,但看起来很糟糕 o_o.
那么告诉我,还有其他方法吗?
注意:我说的是 NDB API,不是旧的

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

推荐答案

使用类属性:A.prop._verbose_name.或 m.__class__.prop._verbose_name.

这篇关于App Engine NDB:如何访问属性的verbose_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆