You probably want .belongs() with a nested ._select(), as shown here: 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#belongs

Anthony

On Monday, June 12, 2017 at 10:27:43 AM UTC-4, J-Michel Angers wrote:
>
> Hi,
> My app goes forward, I have plaisure to develop with web2py.
> But sometimes I don't find myself the solution for very specific search.
>
> My app works well now, I can fill a request, add/remove parts, add/remove 
> attached, calculate price, send this request to collect signatures ....
> Now I try to display in the first "index" page (a SQLFORM.grid), only the 
> requests that interest the user who is at the keybord (for the guitar it's 
> someone else).
> The criteria are :
>  * only the requests that are not closed (and another page or another 
> filter to display old closed requests)
>  * only the requests that were written by this user
>  *  OR the requests that this user HAS already signed OR those that this 
> user HAS TO sign OR those that this user WILL HAVE to sign.
> A request (table = "Demande") has to be signed by many persons and 
> managers (not always the same) => table = "Workflow" (shortcut TDW).
>
> In the first version of my app, each user see all the requests (not 
> closed), and the SQLFORM.grid works well.
>     form = SQLFORM.grid((dbW.Demande.Statut!='Close'), ...)
> In the second version, the user can see his own requests (that he has 
> created) AND also those he HAS TO sign.
>     form = SQLFORM.grid((dbW.Demande.Statut!='Close') &
>                           ((dbW.Demande.CreatedBy==session.CurrentUser)
>                           |(dbW.Demande.NextSign==session.CurrentUser)),
> But now I want to show also the requests that he HAS already signed, OR 
> requests that he WILL HAVE to sign.
> FIRST TRY :
>     form = SQLFORM.grid((dbW.Demande.Statut!='Close') &
>                           ((dbW.Demande.CreatedBy==session.CurrentUser)
>                           |(dbW.Demande.NumDA in (select NumDA from TDW 
> where Responsable==session.CurrentUser)),
> I already knew that this syntax doesn't work.
>
> SECOND TRY :
>     liste_DA_filtre = []
>     for DA in dbW(dbW.TDW.Responsable==session.CurrentUser).select(dbW.TDW
> .NumDA):
>         liste_DA_filtre.append(DA.NumDA)
>     form = SQLFORM.grid((dbW.Demande.Statut!='Close') &
>                           ((dbW.Demande.CreatedBy==session.CurrentUser)
>                           |(dbW.Demande.NumDA in  liste_DA_filtre)),
> Is there any way to do a "in()" ?
>
> THIRD TRY :
>     liste_DA_filtre = []
>     for DA in dbW(dbW.TDW.Responsable==session.CurrentUser).select(dbW.TDW
> .NumDA):
>         liste_DA_filtre.append(DA.NumDA)
>     selection_DA = dbW(dbW.WFDA_DemAchat).select().find(
>              lambda row: row.Statut!='Close' and (row.CreatedBy==session.
> CurrentUser or row.NumDA in liste_DA_filtre))
>     form = SQLFORM.grid((selection_DA, ...)
> I know that this syntax is not correct : SQLFORM.gris needs a request, not 
> a set of data.
> But I wrote this only to check the data that are filtered... and this is 
> exactly the rows I'm looking for.
>

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