The query will happen on every page request, though you can cache 
it<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Caching-selects>.
 
There's another problem, though -- in the list view, the arg in the link is 
the item.id, but in the individual item view, you use that arg to simply 
subset the returned list of items. Note, the item.id (which is the 
auto-incrementing primary key in the database) will not necessarily be 
equivalent to the index of the item in the returned Rows object (e.g., as 
you delete records, the id values in the database will be non-consecutive 
integers).

Anthony

On Monday, September 9, 2013 7:11:14 AM UTC-4, אבי אברמוביץ wrote:
>
> After some tries I got to this, which works fine:
> My question is if the controller "saves" the "items" dict, or it queries 
> for it on every time the view calls it (when moving between pages using the 
> next/previous links?
>
> Thanks.
>
> controller
> def index():
>     items = db(db.t_items).select()
>     return dict(items=items)
>
> view:
>
> {{if request.args(0):}}
> {{item=items[int(request.args(0))-1]}}
> <div class="view_item">
> {{if int(request.args(0)) > 1 :}}
> <a href="{{=URL('default', 'index', args=int(request.args(0))-1)}}"><< 
> Previous item</a>
> {{pass}}
>
> {{if int(request.args(0)) < len(items) :}}
> <a href="{{=URL('default', 'index', args=int(request.args(0))+1)}}">Next 
> item >></a>
> {{pass}}
>
> <h1>{{=item.f_item_name}}</h1>
> <div> <img width="200px" src="{{=URL(r=request, f='download', 
> args=item.f_item_image)}}" /></div>
> <div>{{=item.f_item_description}}</div>
> <div>{{=item.f_item_price}}</div>
> </div>
> {{else:}}
> {{for item in items:}}
> <ul class="grid">
> <h3><a href="{{=URL('default', 'index', args=item.id
> )}}">{{=item.f_item_name}}</a></h3>
> <li>{{=item.f_item_description}}</li>
> <li>{{=item.f_item_price}}</li>
> <li><img width="200px" src="{{=URL(r=request, f='download', 
> args=item.f_item_image)}}" /></li>
> </ul>
> {{pass}}
> {{pass}}
>
> On Sunday, September 1, 2013 8:56:16 PM UTC+3, אבי אברמוביץ wrote:
>>
>> Great, thanks.
>>
>> On Sunday, September 1, 2013 9:40:25 AM UTC+3, אבי אברמוביץ wrote:
>>>
>>> Hi,
>>> I understand the url structure: app/function/view
>>> but assuming I have a list of items on the view, How do I get to a view 
>>> page for each one of them and where can I build that page template? 
>>> Thanks.
>>>
>>

-- 

--- 
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/groups/opt_out.

Reply via email to