Skip to main content

Easy to use reddit like voting system for django models.

Project description

Easy to use reddit like voting system for django models.

Features

  • Does not use GenericForeignKeys (which irritates me when making queries) Has vote_buttons_for templatetag, that generates html code for your object for 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 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.

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()
        objects_with_scores = ObjectsWithScoresManager()
        ...
        ...
  3. Syncdb.

  4. Extend your urls [1].

    import qhonuskan_votes.urls
    from django.conf.urls.defaults import *
    
    urlpatterns = patterns('',
      ...
      ...
      url(r'^votes/', include(qhonuskan_votes.urls)),
    )
  5. Load qhonuskan_votes templatetags from your template. You will need STATIC_PREFIX too.

    {% load qhonuskan_votes static %}
    {% get_static_prefix as STATIC_PREFIX %}
  6. Load default_buttons.css to give little shape to buttons

    <link href="{{STATIC_PREFIX}}default_buttons.css" rel="stylesheet" type="text/css" />
  7. After that line, if you wish you can override some properties

    <style type="text/css">
      div.vote_buttons {
        width: 40px;
        margin-right: 5px;
        float: left;
        border: 1px solid #666;
      }
    </style>
  8. Load jquery to your template

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  9. After all, you can add voting_script template tag to your head section. It generates necessary javascript code for ajax requests.

    {% voting_script %}
  10. use vote_buttons_for_object template tag to create buttons.

    {% for object in objects %}
      <div class="object">
        {% vote_buttons_for object %}
          <div class="text">
            {{ object.text }}
          </div>
      </div>
    {% endfor %}

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

FootNotes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qhonuskan-votes-0.1.3.tar.gz (7.2 kB view hashes)

Uploaded source

Built Distribution

qhonuskan-votes-0.1.3.linux-i686.exe (74.0 kB view hashes)

Uploaded any

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page