Oooops - thank you very much. I think I could have found the difference between "color" and "colors" myself :-(
About the solution: it works very well and it is very import for my project. I have tried to find a solution for several hours and now I have got it in 10 minutes. web2py is great! Thank you both again! 2011/6/27 Anthony <[email protected]> > It's just a typo -- db.color.gr and db.color.id should be db.colors.gr and > db.colors.id. > > Anthony > > On Monday, June 27, 2011 4:35:01 PM UTC-4, mweissen wrote: > >> Hi Massimo, >> looks great. But I got: >> >> web2py™ Version 1.97.1 (2011-06-26 19:25:44) Python Python 2.5.4: >> C:\Web2Py\web2py_win\web2py\**web2py.exe TRACEBACK >> >> >> 1. >> 2. >> 3. >> 4. >> 5. >> 6. >> 7. >> 8. >> 9. >> >> >> Traceback (most recent call last): >> >> >> >> File "gluon/restricted.py", line 192, in restricted >> >> >> >> File >> "C:/Web2Py/web2py_win/web2py/**applications/test16rechte/**controllers/default.py" >> >> <http://127.0.0.1:8000/admin/default/edit/test16rechte/controllers/default.py>, >> line 88, in <module> >> >> >> >> File "gluon/globals.py", line 137, in <lambda> >> >> >> >> File >> "C:/Web2Py/web2py_win/web2py/**applications/test16rechte/**controllers/default.py" >> >> <http://127.0.0.1:8000/admin/default/edit/test16rechte/controllers/default.py>, >> line 84, in newperson >> >> >> >> File "gluon/dal.py", line 4255, in __getattr__ >> >> >> >> File "gluon/dal.py", line 4249, in __getitem__ >> >> >> >> KeyError: 'color' >> >> >> ERROR SNAPSHOT [image: help] >> >> <type 'exceptions.KeyError'>('color'**) >> >> 2011/6/27 Massimo Di Pierro <[email protected]> >> >>> yes >>> >>> db.person.color.requires=IS_**IN_DB(db(db.color.gr=='A'),db.**color.id<http://db.color.id> >>> ,'% >>> (color)s') >>> form=SQLFORM(db.person) >>> >>> On Jun 27, 3:12 pm, Martin Weissenboeck <[email protected]> wrote: >>> > Hi, >>> > I need a SQLFORM with a special drop-box with a subset of values. >>> > >>> > This is a simplified example, the whole problem is a little bit more >>> > complex: Let's make two tables: >>> > >>> > db.define_table('colors', >>> > Field('color'), >>> > Field('gr'), # group >>> > format='%(color)s', >>> > ) >>> > >>> > db.define_table('person', >>> > Field('name'), >>> > Field('color','list:reference colors'), >>> > ) >>> > >>> > I fill the first table: >>> > >>> > def newcolors(): >>> > db.colors.truncate() >>> > db.colors.bulk_insert([ >>> > {'color':'yellow', 'gr':'B'}, >>> > {'color':'green', 'gr':'A'}, >>> > {'color':'blue', 'gr':'A'}, >>> > {'color':'red', 'gr':'B'}, >>> > {'color':'white', 'gr':'B'}, >>> > {'color':'black', 'gr':'B'}, >>> > ]) >>> > >>> > And now there is the SQLFORM for a new person: >>> > >>> > def newperson(): >>> > form=SQLFORM(db.person) >>> > return dict(form=form) >>> > >>> > The form contains a SELECT/OPTION multiple drop-box for the colors >>> *black to >>> > yellow.* >>> > >>> > My question: is it possible to have three different forms >>> > >>> > - a drop-box which contains only the colors of group A (green, blue) >>> > - a drop-box which contains only the colors of group B (yellow, red, >>> > white, black) >>> > - a drop-box with all color >>> > >>> > Something like >>> > >>> > form=SQLFORM(db.person, colors_for_select=[1,2]) >>> > >>> > Regards, >>> > Martin >>> >> >> >> >>

