Cool. But I am new to both python and web2py. I did something like def showABName(r): a_row = db.table_a[r.a_id] b_row = db.table_b[r.b_id] return a_row.name[0:20] + '-' + b_row.name
and in the table definition db.define_table('a_b', Field('a_id', db.table_a), Field('b_id', db.table_b), Field('displayorder', 'integer', required=True), format=lambda r : showABName(r)) It worked!!! But I am sure there is a simpler way. Also I am not sure why I couldn't call the showName() directly with r argument. It gives me an error. Probably another python thing I don't know. Anyway thanks a lot. Thanks, Steve On Oct 30, 4:06 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > format can be a function that takes the record returns a string. > > On Oct 29, 4:05 pm, Steve <stephenga...@gmail.com> wrote: > > > Hi all, > > > I am able to solve the issue. > > > I just removed the following line. > > > db.table_c.a_b_id.requires = IS_NOT_IN_DB(db, db.a_b) > > > Now, I am getting the drop down. But the drop down shows the id of > > 'a_b' table. But ideally I would like the combination of a.name and > > b.name in the drop > > down for 'a_b_id' in the 'table_c'. > > > By changing the format of 'a_b' as '%(a_id)s - %(b_id)s', I am able to > > show the ids combination. But I want to show the name combination to > > make the drop down more meaningful. > > > Thanks, > > Steve. > > > On Oct 29, 6:46 pm, Steve <stephenga...@gmail.com> wrote: > > > > Hi, > > > > I have the following table structure in my db.py. > > > > db.define_table('table_a', > > > Field('x_id', db.table_x), > > > Field('name', length=200, required=True), > > > Field('description', length=300), > > > Field('displayorder', 'integer', required=True), > > > format='%(name)s') > > > > db.define_table('table_b', > > > Field('name', length=45, required=True), > > > Field('description', length=200), > > > format='%(name)s') > > > > db.define_table('a_b', > > > Field('a_id', db.table_a), > > > Field('b_id', db.table_b), > > > Field('displayorder', 'integer', required=True), > > > format='%(id)s') > > > > db.define_table('user', > > > Field('user_id', 'integer', required=True), > > > Field('name', length=60, required=True), > > > format='%(name)s') > > > > db.define_table('table_c', > > > Field('a_b_id', db.a_b), > > > Field('user_id', db.user), > > > Field('content', 'text', required=True), > > > Field('content', 'text', required=True)) > > > > db.table_c.a_b_id.requires = IS_NOT_IN_DB(db, db.a_b) > > > > Here, 'table_a' and 'table_b' have many to many mapping. Table 'a_b' > > > is the mapping table. Now in > > > 'table_c', I am referring to table 'a_b'. (the mapping table) > > > > While inserting into 'table_c', I am not getting the drop down for the > > > 'a_b_id' column. But for the 'user_id' column, I am getting the drop > > > down. I am not sure where things are going wrong. Any help is > > > appreciated. > > > > Ideally I would like the combination of a.name and b.name in the drop > > > down for 'a_b_id' in the 'table_c' > > > > By the way, web2py is an amazing piece of work. So far my experience > > > has been great. > > > > Thanks, > > > Steve. > >