Re: [web2py] Re: DAL db.table.field.contains

2013-11-22 Thread Richard Vézina
I guess because his Author reference field is of type list:reference ?!

Richard


On Thu, Nov 21, 2013 at 3:12 PM, Niphlod niph...@gmail.com wrote:

 why contains instead of == ?
 db(db.Book.Author == Author.id).select(db.Book.ALL, orderby=db.Book.Name)


 On Thursday, November 21, 2013 4:31:53 PM UTC+1, Richard wrote:

 Ok, figured out, I think, what happen is that you use index to get record
 in l (that actually is a pretty bad variable name since it could be
 confused with 1 - ONE with some fonts)... By using an index you always get
 only the first row in rows because your l variable is a rows object that
 contains many row(s)... So you only get the first one each time.

 You don't have to make complicated code like so...

 This should work better :

 thead = THEAD(TR(TH(Author), TH(Books)))
 tr = []
 for Author in AL:
 rows = db(db.Book.Author.contains(Author.id)).select(db.Book.ALL,
 orderby=db.Book.Name)

 tr.append(TR(TD(Author.Name), TD([row.Name for row in rows])))

 table = TABLE(thead, TBODY(tr))

 return dict(table=table)

 In your view :

 {{=table}}



 Richard





 On Thu, Nov 21, 2013 at 10:16 AM, BlueShadow kevin@gmail.com wrote:

 def Authors():
 AL=db().select(db.Author.ALL, orderby=db.Author.Name)
 TheList=[]
 for Author in AL:
 l=db(db.Book.Author.contains(Author.id)).select(db.Book.ALL,
 orderby=db.Book.Name)
 if len(l)0:
 TheList.append([l[0]])
 else:
 TheList.append([])
 return dict(AL=AL,BookList=TheList)
 here is my controller funktion
 and my view:
 table
 {{i=0}}
 {{for Author in AL:}}
 tr
 td{{=Author.Name}}/tdtd/td
 /tr
 {{for b in BookList[i]:}}
 tr
 td/tdtd{{=b.Name}}/td
 /tr
 {{pass}}
 {{i+=1}}
 {{pass}}
 /table
 its supposed to give an alphabetical list of all authors which it does.
 and list all their books (only one is displayed)


  --
 Resources:
 - 
 http://web2py.comhttp://www.google.com/url?q=http%3A%2F%2Fweb2py.comsa=Dsntz=1usg=AFQjCNE7x6wflFTAQ11b-FhtMwFfvltXeg
 - 
 http://web2py.com/bookhttp://www.google.com/url?q=http%3A%2F%2Fweb2py.com%2Fbooksa=Dsntz=1usg=AFQjCNFAv433a0RL4nfaYxTbZ4cHi4Q78A(Documentation)
 - 
 http://github.com/web2py/web2pyhttp://www.google.com/url?q=http%3A%2F%2Fgithub.com%2Fweb2py%2Fweb2pysa=Dsntz=1usg=AFQjCNHSwgWBkjuiIoo30014e8BB_iCDag(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 web2py+un...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.


  --
 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 web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: DAL db.table.field.contains

2013-11-22 Thread Kevin Bethke
thats why.
thanks richard for your solution it works perfectly.

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: DAL db.table.field.contains

2013-11-22 Thread Richard Vézina
:)


On Fri, Nov 22, 2013 at 10:20 AM, Kevin Bethke kevin.bet...@gmail.comwrote:

 thats why.
 thanks richard for your solution it works perfectly.

 --
 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 web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: DAL db.table.field.contains

2013-11-21 Thread Niphlod
why contains instead of == ?
db(db.Book.Author == Author.id).select(db.Book.ALL, orderby=db.Book.Name)

On Thursday, November 21, 2013 4:31:53 PM UTC+1, Richard wrote:

 Ok, figured out, I think, what happen is that you use index to get record 
 in l (that actually is a pretty bad variable name since it could be 
 confused with 1 - ONE with some fonts)... By using an index you always get 
 only the first row in rows because your l variable is a rows object that 
 contains many row(s)... So you only get the first one each time.

 You don't have to make complicated code like so...

 This should work better :

 thead = THEAD(TR(TH(Author), TH(Books)))
 tr = []
 for Author in AL:
 rows = db(db.Book.Author.contains(Author.id)).select(db.Book.ALL, 
 orderby=db.Book.Name)

 tr.append(TR(TD(Author.Name), TD([row.Name for row in rows])))

 table = TABLE(thead, TBODY(tr))

 return dict(table=table)

 In your view :

 {{=table}}



 Richard





 On Thu, Nov 21, 2013 at 10:16 AM, BlueShadow kevin@gmail.comjavascript:
  wrote:

 def Authors():
 AL=db().select(db.Author.ALL, orderby=db.Author.Name)
 TheList=[]
 for Author in AL:
 l=db(db.Book.Author.contains(Author.id)).select(db.Book.ALL, 
 orderby=db.Book.Name)
 if len(l)0:
 TheList.append([l[0]])
 else:
 TheList.append([])
 return dict(AL=AL,BookList=TheList)
 here is my controller funktion
 and my view:
 table
 {{i=0}}
 {{for Author in AL:}}
 tr
 td{{=Author.Name}}/tdtd/td
 /tr
 {{for b in BookList[i]:}}
 tr
 td/tdtd{{=b.Name}}/td
 /tr
 {{pass}}
 {{i+=1}}
 {{pass}}
 /table
 its supposed to give an alphabetical list of all authors which it does.
 and list all their books (only one is displayed)


  -- 
 Resources:
 - 
 http://web2py.comhttp://www.google.com/url?q=http%3A%2F%2Fweb2py.comsa=Dsntz=1usg=AFQjCNE7x6wflFTAQ11b-FhtMwFfvltXeg
 - 
 http://web2py.com/bookhttp://www.google.com/url?q=http%3A%2F%2Fweb2py.com%2Fbooksa=Dsntz=1usg=AFQjCNFAv433a0RL4nfaYxTbZ4cHi4Q78A(Documentation)
 - 
 http://github.com/web2py/web2pyhttp://www.google.com/url?q=http%3A%2F%2Fgithub.com%2Fweb2py%2Fweb2pysa=Dsntz=1usg=AFQjCNHSwgWBkjuiIoo30014e8BB_iCDag(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 web2py+un...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: DAL db.table.field.contains

2013-11-21 Thread BlueShadow
def Authors():
AL=db().select(db.Author.ALL, orderby=db.Author.Name)
TheList=[]
for Author in AL:
l=db(db.Book.Author.contains(Author.id)).select(db.Book.ALL, orderby
=db.Book.Name)
if len(l)0:
TheList.append([l[0]])
else:
TheList.append([])
return dict(AL=AL,BookList=TheList)
here is my controller funktion
and my view:
table
{{i=0}}
{{for Author in AL:}}
tr
td{{=Author.Name}}/tdtd/td
/tr
{{for b in BookList[i]:}}
tr
td/tdtd{{=b.Name}}/td
/tr
{{pass}}
{{i+=1}}
{{pass}}
/table
its supposed to give an alphabetical list of all authors which it does.
and list all their books (only one is displayed)


-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: DAL db.table.field.contains

2013-11-21 Thread Richard Vézina
Ok, figured out, I think, what happen is that you use index to get record
in l (that actually is a pretty bad variable name since it could be
confused with 1 - ONE with some fonts)... By using an index you always get
only the first row in rows because your l variable is a rows object that
contains many row(s)... So you only get the first one each time.

You don't have to make complicated code like so...

This should work better :

thead = THEAD(TR(TH(Author), TH(Books)))
tr = []
for Author in AL:
rows = db(db.Book.Author.contains(Author.id)).select(db.Book.ALL,
orderby=db.Book.Name)

tr.append(TR(TD(Author.Name), TD([row.Name for row in rows])))

table = TABLE(thead, TBODY(tr))

return dict(table=table)

In your view :

{{=table}}



Richard





On Thu, Nov 21, 2013 at 10:16 AM, BlueShadow kevin.bet...@gmail.com wrote:

 def Authors():
 AL=db().select(db.Author.ALL, orderby=db.Author.Name)
 TheList=[]
 for Author in AL:
 l=db(db.Book.Author.contains(Author.id)).select(db.Book.ALL,
 orderby=db.Book.Name)
 if len(l)0:
 TheList.append([l[0]])
 else:
 TheList.append([])
 return dict(AL=AL,BookList=TheList)
 here is my controller funktion
 and my view:
 table
 {{i=0}}
 {{for Author in AL:}}
 tr
 td{{=Author.Name}}/tdtd/td
 /tr
 {{for b in BookList[i]:}}
 tr
 td/tdtd{{=b.Name}}/td
 /tr
 {{pass}}
 {{i+=1}}
 {{pass}}
 /table
 its supposed to give an alphabetical list of all authors which it does.
 and list all their books (only one is displayed)


  --
 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 web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.