Try something like that, just before SQLFORM(...)

db.changecontrol.project_id.requires =
IS_IN_DB(db(db.Project.account_id==auth.user_id), db.Project.id,'%(name)s
(%(id)d)',zero='Select ...')

On Tue, Sep 8, 2015 at 8:55 PM, Vincent Zaffiro <[email protected]>
wrote:

> I am trying to utilize the SQLFORM magic as much as possible and ran into
> the below scenario and hopeful that the SQLFORM can handle it.
>
>
>
>
> Scenario
>
>
>    -  I have an account that can have multiple projects which is defined
>    here:
>
>
>
> db.define_table(*'Account'*,
>                 Field(
>
>                 Field(*'name'*, type=*'string'*, requires=IS_NOT_EMPTY()),
>                 Field(
>
>                 Field(*'is_active'*, type=*'boolean'*),
>                 auth.signature,
>
>
>                 auth.signature,
>
>                 format=
> *'%(name)s'                 *
>
>                 )
>
>
>
> db.define_table(*'Project'*,
>                 Field(
>
>                 Field(*'name'*, type=*'string'*),
>                 Field(
>
>                 Field(*'description'*, type=*'string'*),
>                 Field(
>
>                 Field(*'account_id'*, db.Account),
>                 auth.signature,
>
>
>                 auth.signature,
>
>                 format=*'%(name)s'
>                 *
>
>                 )
>
>
>
>    - When a user is created they are assigned to an account through
>    auth_user extended fields. in this example the user's account_id is 1.
>
>
>
>
>    - I made a changecontrol model that references the project model.
>
> db.define_table(*'changecontrol'*,
>                 Field(
>
>                 Field(*'project_id'*, db.Project, label=*'Project Name'*),
>                 Field(
>
>                 Field(*'name'*, type=*'string'*, requires=IS_NOT_EMPTY()),
>                 auth.signature,
>
>
>                 auth.signature,
>
>                 format=*'%(name)s'
>                 *
>
>                 )
>
>
>
> My controller looks like this:
>
> *def *new():
>     form = SQLFORM(db.changecontrol).process()
>
>     return locals()
>
>
>
>  Question
>
>       I would like the list of projects to appear in a dropdown that are
> only associated with the Logged in user’s account (for example account_id
> would be 1).
>
>
>
>       How do I filter the projects on the form to only show the projects
> that are associated with an account_id  of 1?
>
> Thanks in advance!
>
> --
> 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.
>



-- 
Massimiliano

-- 
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