Getting a bit peeved now;
I have a model and a class thats just storing a get request in the database; basic tracking.
class SearchRec(db.Model):
WebSite = db.StringProperty()#required=True
WebPage = db.StringProperty()
CountryNM = db.StringProperty()
PrefMailing = db.BooleanProperty()
DateStamp = db.DateTimeProperty(auto_now_add=True)
IP = db.StringProperty()
class AddSearch(webapp.RequestHandler):
def get(self):
searchRec = SearchRec()
searchRec.WebSite = self.request.get('WEBSITE')
searchRec.WebPage = self.request.get('WEBPAGE')
searchRec.CountryNM = self.request.get('COUNTRY')
searchRec.PrefMailing = bool(self.request.get('MAIL'))
searchRec.IP = self.request.get('IP')
Bool has my biscuit; I thought that setting bool(self.reque….) would set the type of the string but no matter what I pass it it still stores it as TRUE in the database.
I had the same issue with using required=True on strings for the model; the damn thing kept saying that nothing was being passed… but it had.
Ta
You’ve added a lot of layers of complication to understanding what the bool() build-in function does. Why don’t you test it out directly on the command-line, before embedding it deep in your google app engine code.
What you’d discover is that the bool() function uses python’s truth values:
http://docs.python.org/library/stdtypes.html#truth-value-testing
In particular – any non-empty string is
True.