IS_IN_DB(db.t_city, ...) ? should be
IS_IN_DB(db, ....) On Nov 17, 1:06 pm, Renato Ramiro <renato....@gmail.com> wrote: > I asked the same question in the > web2py-users-brazil<http://groups.google.com/group/web2py-users-brazil?hl=pt-BR> > . > > And this was the suggestion: > > ########################### > db.t_hospital.f_group.requires = IS_IN_DB(db.t_city, 't_city.id', > db.t_city.f_group, zero=T('[Choose an item from the list]')) > > db.t_hospital.f_city.requires = IS_IN_DB(db.t_city, 't_city.id', > db.t_city.f_name, zero=T('[Choose an item from the list]')) > ########################### > > But I have an error: > --------------------------------------------- > Traceback (most recent call last): > File "/home/www-data/web2py/gluon/restricted.py", line 194, in > restricted > exec ccode in environment > File "/home/www-data/web2py/applications/indicadores/controllers/ > default.py", line 39, in <module> > File "/home/www-data/web2py/gluon/globals.py", line 149, in <lambda> > self._caller = lambda f: f() > File "/home/www-data/web2py/gluon/tools.py", line 2456, in f > return action(*a, **b) > File "/home/www-data/web2py/applications/indicadores/controllers/ > default.py", line 26, in hospital_manage > form = SQLFORM.grid(db.t_hospital,onupdate=auth.archive, > columns=columns, details=True, editable=True, deletable=True) > File "/home/www-data/web2py/gluon/sqlhtml.py", line 1445, in grid > _class='web2py_form' > File "/home/www-data/web2py/gluon/sqlhtml.py", line 862, in __init__ > inp = self.widgets.options.widget(field, default) > File "/home/www-data/web2py/gluon/sqlhtml.py", line 217, in widget > options = requires[0].options() > File "/home/www-data/web2py/gluon/validators.py", line 459, in > options > self.build_set() > File "/home/www-data/web2py/gluon/validators.py", line 440, in > build_set > fields = [f for f in self.dbset.db[self.ktable]] > File "/home/www-data/web2py/gluon/dal.py", line 4921, in __getattr__ > return self[key] > File "/home/www-data/web2py/gluon/dal.py", line 4865, in __getitem__ > return dict.__getitem__(self, str(key)) > KeyError: 'db' > --------------------------------------------- > > 2011/11/17 DenesL <denes1...@yahoo.ca> > > > > > > > > > > > > > It sound like you need to create three tables instead, > > one for cities, one for groups and one for city-group combos. > > > On Nov 17, 6:52 am, Renato Ramiro <renato....@gmail.com> wrote: > > > In my application, I have two tables: City and Hospital. > > > > In the table City, there are two fields: name and group. > > > And the table Hospital, there are name, number of beds, number of medics, > > > and city (foreign key). > > > > Through the wizard, I did this (below): > > > > Field('f_city', type='reference t_city', > > > label=T('City')), > > > > And manually I added this (below) > > > > Field('f_group', type='reference t_city', > > > label=T('Group')), > > > > At the moment of creating a Hospital, I have two combobox. One labeled > > > city, the other labeled group, but the second won't show the group. It > > > shows the city instead. > > > > Is there some way to show the group? > > > -- > > > Renato Ramiro > > -- > Renato Ramiro