yes

db.person.color.requires=IS_IN_DB(db(db.color.gr=='A'),db.color.id,'%
(color)s')
form=SQLFORM(db.person)

On Jun 27, 3:12 pm, Martin Weissenboeck <mweis...@gmail.com> 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

Reply via email to