[web2py] empty field saved as NULL or ' '
I have the flowing two field definitions: Field('code_1', default='', label=T("Code 1"), requires=[IS_EMPTY_OR(IS_NOT_IN_DB(db, 'product.code_1',error_message=T('Code 1 already in use'),ignore_common_filters=False)),IS_LENGTH(maxsize=15)]), Field('code_2', default='',label=T("Code 2")), However when both are empty on a form , code_1 is saved as null but code_2 saved as ' ' in the database (PostgreSQL) So db(db.product.code_1==' ') gives different results then db(db.product.code_2==' ') How do I get an empty string ' ' also for code_1 in db ? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] empty field
how come i have to test an empty string field within a try|except block like this: try: b = q.create_lecture_foldername!=None except: b = False if b: something instead of the more straight forward: if (q.create_lecture_foldername!=None): something because if i try the previous simpler approach, it blows giving me the error: if (usr.create_lecture_foldername!=None): File /opt/web-apps/web2py/gluon/dal.py, line 3851, in __getattr__ return self[key] File /opt/web-apps/web2py/gluon/dal.py, line 3842, in __getitem__ return dict.__getitem__(self, key) KeyError: 'create_lecture_foldername' same as if i try to use the len() method: if (usr.create_lecture_foldername.len()0): File /opt/web-apps/web2py/gluon/dal.py, line 3851, in __getattr__ return self[key] File /opt/web-apps/web2py/gluon/dal.py, line 3842, in __getitem__ return dict.__getitem__(self, key) KeyError: 'create_lecture_foldername' so isn't there a better way then the try|except block. lucas
[web2py] empty field crud.update(db.table)
I am using the Pengoworks auto complete plugin. In my model file I have: db.address.city.widget=lambda self,value:INPUT(_type='text',_id='city',_class='ac_input',_name='city_name',requires=self.requires) In web2py_ajax.html: jQuery('#city').autocomplete('/cms/handlers/cityAC',{maxItemsToShow: 12}); In a handlers controller: def cityAC(): q='' if request.vars: q=request.vars.q if not q: return q rows=db(db.city.name.like('%s% %'%q.capitalize())).select(db.city.name,orderby=db.city.name) r='' for row in rows: r='%s%s\n'%(r,row.name) return r The auto complete works in empty forms, however, when I use crud.update(db.address,...) the city field is empty, whereas the database record contains a value for city. I guess I have to adjust the cityAC() function, but I don't know how... Kind regards, Annet.