Hi guys,
I am pretty new to web2py and really enjoy learning this neat
framework. However, I've just encountered a problem, while trying to
developing a simple image gallery.
I want to put a simple counter under each image, but could not figure
out how to do so. Here are the relevant code
db.define_table('image',
Field('title','string', required=True),
Field('file', 'upload', required=True),
Field('category',required=True),
Field('created_on', 'datetime', default=request.now),
Field('created_by', db.auth_user, default=auth.user_id),
Field('visits', 'integer', default=0),
format='%(name)s')
------C O N T R O L L E R (unsuccessful) ------------------
def show():
image = db.image(request.args(0)) or redirect(URL('index'))
db.comment.image_id.default = image.id
form = crud.create(db.comment,
message='your comment is posted',
next=URL(args=image.id))
comments = db(db.comment.image_id==image.id).select()
visits = db.image(request.args(0)).visits
visits.viist(+=1)
#visits = db.image(request.args(0)).update_record(visits)
return dict(image=image, comments=comments, form=form,
visits=visits)
#---V I E W---------------
{{extend 'layout.html'}}
<h1>Photo: {{=image.title}}</h1>
<center>
<img width="200px"
src="{{=URL('download', args=image.file)}}" />
<p>Visits: {{=visits}}</p>
</center>
{{if len(comments):}}
<h2>Comments</h2><br /><p>
{{for comment in comments:}}
<p>{{=comment.author}} Wrote: <i>{{=comment.body}}</i></p>
{{pass}}</p>
{{else:}}
<h2>No comments posted yet</h2>
{{pass}}
<h2>Post a comment</h2>
{{=form}}
----------------------------
I appreciate your help.