Massimo,

may i use multiple fields on SQLFORM.factory?

may be a solution to create a form with the functionality of set a state 
and automatically fill a dropdown with all cities from selected state, set 
a city and automatically fill a dropdown with all zones from that selected 
cities... ????

#my db.py

Adverts_Type = db.define_table('adverts_type', 
                           Field('label', 'string'),
                           Field('description', 'text'),
                         )

States = db.define_table('states',
                           Field('label', 'string'),
                         )

Cities = db.define_table('cities',
                           Field('state_id', db.states),
                           Field('label', 'string'),
                         )

Zones = db.define_table('zones', 
                           Field('city_id', db.cities),
                           Field('label', 'string'),
                         )


Adverts = db.define_table('adverts',
                           Field('owner_id', 'integer'),
                           Field('type_id', adverts_type),
                           Field('description', 'text'),
                           Field('image', 'upload'),
                           Field('city_id', 'integer'),
                           Field('zone_id', 'integer'),
                         )



Adverts.type_id.requires = IS_IN_DB(db(Adverts_Type), 'adverts_type.id', 
'%(label)s')
Cities.states_id.requires = IS_IN_DB(db(States), 'states.id', '%(label)s')
Zones.city_id.requires = IS_IN_DB(db(Cities), 'cities.id', '%(label)s')


Em quarta-feira, 1 de fevereiro de 2012 18:35:38 UTC-2, Massimo Di Pierro 
escreveu:
>
> Something like this? 
>
> db.define_table('cities', 
>     Field('name'), 
>     Field('state'), 
>     format = '%(name)s' 
> ) 
>
>
> form = SQLFORM.factory(Field('choose_city','reference cities')) 
>
> On Feb 1, 2:25 pm, shartha <[email protected]> wrote: 
> > So the problem is two folds. I have defined a simple table as in: 
> > 
> > db = DAL("sqlite://storage.sqlite") 
> > 
> > db.define_table('cities', 
> >     Field('name'), 
> >     Field('state'), 
> > ) 
> > 
> > Now I'd like to have a drop-down list in my view that reads from the 
> > name filed of the database cities. How can I achieve this? Any help 
> > would be highly appreciated. 
> > 
> > Thanks! 
> > S.

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to