IS_IN_DB for multiple tables

10 views
Skip to first unread message

phneoix

unread,
Jul 9, 2009, 12:53:07 AM7/9/09
to web2py Web Framework
hi,
i am having about 8 different lookup tables in my database. i need
to validate whether the entry is in any one of the 8 tables.

Thanks.

mdipierro

unread,
Jul 9, 2009, 2:03:43 AM7/9/09
to web2py Web Framework
only validate or you need a selection dropdown? You need your own
validator. Look into the code for IS_IN_DB and it is not difficult to
make your own.

phneoix

unread,
Jul 9, 2009, 2:25:31 AM7/9/09
to web2py Web Framework
only need to validate.

mdipierro

unread,
Jul 9, 2009, 9:35:13 AM7/9/09
to web2py Web Framework
Something like this?

class IS_THERE:
def __init__(db,fields, error_message='not there'):
self.db=db
self.fields=fields
self.error_message=error_message
def __call__(self,value):
for field in self.fields:
if self.db(field==value).count(): return (value,None)
return (value,self.error_message)

requires=IS_THERE(db,
(db.table1.field1,db.table2.field2,...db.table8,field8))
Reply all
Reply to author
Forward
0 new messages