App engine NDB: how to access verbose_name of a property
Asked Answered
D

1

6

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

Disappearance answered 23/6, 2012 at 2:13 Comment(1)
Doesn't seem very hacky to me, if you actually need to inspect the name during usage rather than declaration.Dominik
J
8

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

Jabiru answered 23/6, 2012 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.