I am making a small app that lets users vote items either up or down. I'm using Django (and new to it!).
I am just wondering, what is the best way to present the upvote link to the user. As a link, button or something else?
I have already done something like this in php with a different framework but I'm not sure if I can do it the same way. Should I have a method for up/down vote and then display a link to the user to click. When they click it, it performs the method and refreshes the page?
Here's the gist of my solution. I use images with jQuery/AJAX to handle clicks. Strongly influenced by this site. There's some stuff that could use some work (error handling in the client, for example -- and much of it could probably be refactored) but hopefully the code is useful to you.
The HTML:
The jQuery:
The Django view that handles the AJAX request:
And the relevant parts of the Thread model:
Something else, what about an image?
Perhaps you could better use ajax to invoke a method to save the vote, and not refresh anything at all.
This is what comes to my mind.
Just plug and play:
Whatever you do, make sure that it's submitted by POST and not GET; GET requests should never alter database information.