Model
db.define_table('content',
Field('username'),
Field('text', 'text'),
Field('file', 'upload'),
Field('userpicture'),
Field('time', 'datetime', update=request.now),
Field('userid', readable=False),
Field('votesup', 'integer', default=0),
Field('votesdown', 'integer', default=0)
)
Controller (default.py)
def feed():
#postform
postform = crud.create(db.content, next='feed')
postform['_id']='postform'
...
votesup = postform.element('input', _name='votesup')
votesup['_type']='hidden'
votesdown = postform.element('input', _name='votesdown')
votesdown['_type']='hidden'
contents = db().select(db.content.ALL, orderby=~db.content.id)
return dict(postform=postform, contents=contents)
def voteup():
item = db.content[request.vars.id]
new_votes = item.votesup + 1
item.update_record(votesup=new_votes)
return str(new_votes)
View (default/feed.html)
{{for content in contents:}}
...
<span onclick="jQuery('#postform').val('{{=content.id}}'); ajax('voteup',
['votesup'], 'content{{=content.id}}');" style='padding:10px;'>
<img src='../static/images/thumbsup.png' style='height:20px;
width:20px;'/></span>
<span id='content{{=content.id}}' >{{=content.votesup}}</span>
{{pass}}
When I click the image in the view "thumbsup.png", the votesup count
doesn't increase... what am i doing wrong?
--
---
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.