miratcan / qhonuskan-votes

Simple reddit like voting system without usage off GenericForeignKeys. Built for linkfloyd project.
Other
30 stars 11 forks source link

=============== Qhonuskan-Votes

Easy to use reddit like voting system for django models.

Features

Quick Implementation Guide

  1. Add qhonuskan_votes to your INSTALLED_APPS.

    ::

    INSTALLED_APPS = ('...', '...', 'qhonuskan_votes')

  2. 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()

    Add objects before all other managers to avoid issues mention in http://stackoverflow.com/a/4455374/1462141

    objects = models.Manager()

    For just a list of objects that are not ordered that can be customized.

     objects_with_scores = ObjectsWithScoresManager()

    For a objects ordered by score.

    sort_by_score = SortByScoresManager() ... ...

  3. Syncdb.

  4. Extend your urls [#]_. ::

    import qhonuskan_votes.urls from django.conf.urls.defaults import *

    urlpatterns = patterns('', ... ... url(r'^votes/', include(qhonuskan_votes.urls)), )

  5. Create the list in you view. Use

    ::

    For a regular list of items without votes from your model use the following:

    item_list_no_score = Items.objects.all()

    For a list with scores that can be customized with use the following:

    item_list_unordered_with_scores = Items.objects_with_scores.all()

    to customize the order by a field unique to your model. So something like this:

    item_list_unordered_with_scores = Items.objects_with_scores.all().order_by(-date_created)

    To obtain a list of items sorted by vote counts like (1,0,-1) like Reddit:

    item_list_ordered__scores = Items.sort_by_score.all()

  6. Load qhonuskan_votes templatetags from your template. You will need STATIC_PREFIX too.

    ::

    {% load qhonuskan_votes static %} {% get_static_prefix as STATIC_PREFIX %}

  7. Load default_buttons.css to give little shape to buttons

    ::

  8. After that line, if you wish you can override some properties

    ::

  9. Load jquery to your template

    ::

  10. After all, you can add voting_script template tag to your head section. It generates necessary javascript code for ajax requests.

    ::

    {% voting_script %}

  11. use vote_buttons_for_object template tag to create buttons.

    ::

    {% for object in objects %}

    {% vote_buttons_for object %}
    {{ object.text }}

    {% endfor %}

For further information you can inspect example project at root of the repository.

Contribution

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:

FootNotes

.. [#] 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.