Thanks a log pbreit. Your suggested perfectly solved my problem. I fiddled a bit with update_record but had difficulty who to grab the field in database, in order to update it. Since this seem to be a pretty common task (and difficulty for noobs), perhaps It would be good if this example somehow be incorporated into the web2py chapter about DAL or example codes.
Cheers On Mar 6, 1:53 am, pbreit <pbreitenb...@gmail.com> wrote: > Wow, hard to say but you definitely have some problems. For example, the > typo in "visits.viist(+=1)". Are you getting error messages or is it just > not doing what you want? > > Something like this perhaps? This code only adds one line to what is shown > in the Book: image.update_record(visits=image.visits + 1). One thing to do > is only make one "db.table" call per controller. You usually only need to > access the database once per table. And in this case, you only need to do an > image.update_record to increment the visits. > > 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() > image.update_record(visits=image.visits + 1) > return dict(image=image, comments=comments, form=form) > > === show.html === > ... > <p>Visits: {{=image.visits}}</p> > ...