Easy to use reddit like voting system for django models.
Does not use GenericForeignKeys (which irritates me when making queries)
Has "vote_buttons_for" template tag, that generates html code for displaying vote buttons.
Has, default_buttons.css which gives a shape your buttons as default, but you can override.
Has, voting_script template tag, it generates javascript code to make ajax requests for voting. Automatically finds qhonuskan_votes views.
voting_script tag also renders overridable show_not_authenticated_error javascript function, so you can use your own error windows (jquery-ui etc.) via overriding it.
Default buttons are pure css, there is no images. So it's lite.
Add qhonuskan_votes to your INSTALLED_APPS.
::
INSTALLED_APPS = ('...', '...', 'qhonuskan_votes')
Add VotesField, and add ObjectsWithScoresManager to your model.
::
from django.db import models from qhonuskan_votes.models import VotesField
class MyModel(models.Model): votes = VotesField()
objects = models.Manager()
objects_with_scores = ObjectsWithScoresManager()
sort_by_score = SortByScoresManager() ... ...
Syncdb.
Extend your urls [#]_. ::
import qhonuskan_votes.urls from django.conf.urls.defaults import *
urlpatterns = patterns('', ... ... url(r'^votes/', include(qhonuskan_votes.urls)), )
Create the list in you view. Use
::
item_list_no_score = Items.objects.all()
item_list_unordered_with_scores = Items.objects_with_scores.all()
item_list_unordered_with_scores = Items.objects_with_scores.all().order_by(-date_created)
item_list_ordered__scores = Items.sort_by_score.all()
Load qhonuskan_votes templatetags from your template. You will need STATIC_PREFIX too.
::
{% load qhonuskan_votes static %} {% get_static_prefix as STATIC_PREFIX %}
Load default_buttons.css to give little shape to buttons
::
After that line, if you wish you can override some properties
::
Load jquery to your template
::
After all, you can add voting_script template tag to your head section. It generates necessary javascript code for ajax requests.
::
{% voting_script %}
use vote_buttons_for_object template tag to create buttons.
::
{% for object in objects %}
{% endfor %}
For further information you can inspect example project at root of the repository.
You liked this project? Nice. Let's start with provide your virtual environment. You can install all you need dependencies::
$ pip install -r requirements/development.txt
We have some important conditions during the development of the project:
.. [#] To use the views for up voting and down voting you include the urls.py in your website's url patterns. You can serve qhonuskan_votes views wherever you want. Javascript files updates automatically to find qhonuskan_votes views.