1

I am aware of how to convert the strings posted from my form to some of the common types, eg (Boolean and Integer):

age = int(self.request.get("age")) #convert to integer
opt_in = self.request.get("opt_in") == 'on' #convert to boolean

My questions is how about how to convert to some of the less common types, ie 1. EmailProperty 2. FloatProperty 3. PhoneNumberProperty 4. DateProperty

TimothyAURA
  • 1,329
  • 5
  • 21
  • 44

1 Answers1

1

You tagged your question with , but the EmailProperty and PhoneNumberProperty are actually db properties, not ndb ones:

They have Unicode sort order, so I guess you could use StringProperty for them, no conversion needed.

For DateProperty you need a datetime.date() value type, see How to convert a time string in a Google AppEngine db.TimeProperty?

So you just need to convert your string representation to a datetime.date().

For FloatProperty see Parse String to Float or Int.

Community
  • 1
  • 1
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • Interesting. I am still trying to understand the difference of ndb vs db. The Google docs tend to reference both interchangeably. I know there is a table of db to ndb namespaces/parameters to migrate. I will look more into this thanks Dan. – TimothyAURA Mar 02 '17 at 06:53
  • See http://stackoverflow.com/questions/12852442/pros-and-cons-of-db-and-ndb-in-google-app-engine/12855111#12855111 and http://stackoverflow.com/questions/23645572/app-engine-difference-between-ndb-and-datastore/23646875#23646875 – Dan Cornilescu Mar 02 '17 at 14:18