I am trying to write a restful service of my own for google app engine. I am dynamically fetching form data and saving the model. To get the attribute list , I am doing
Contact.__properties
{'name': StringProperty('name', required=True), 'email': StringProperty('email', required=True)}
I can do this to find the type of the attribute
(Pdb) type(Contact._properties['name']) is ndb.StringProperty
True
But how can I find if it is required = True or False
What is the type of the output of Contact._properties, how do I decipher it .
Although poorly documented, there is an introspection API for NDB models; simply use the name of the configuration option with an underscore prefixed:
Contact._properties['name']._required
is the value of the required
option.
The underscores do not signify 'privacy' here but are used to avoid clashing with names from the model itself (e.g. if name
were a StructuredProperty
referencing another model with a required
property you wouldn't otherwise be able to access the required
option).