A Django app to add star ratings to models.
Project description
Python 3 compatible ratings for Django.
Add ratings to any Django model with a template tag.
Installation
Install from PyPI:
pip install django-star-ratings
add star_ratings to INSTALLED_APPS:
INSTALLED_APPS = ( ... 'star_ratings' )
sync your database:
python manage.py migrate
add the following to your urls.py:
url(r'^ratings/', include('star_ratings.urls', namespace='ratings', app_name='ratings')),
Make sure 'django.core.context_processors.request', is in TEMPLATE_CONTEXT_PROCESSORS.
Usage
Add the following javascript and stylesheet to your template
{% load static %} <html> ... <link rel="stylesheet" href="{% static 'star-ratings/css/star-ratings.css' %}"> <script type="text/javascript" src="{% static 'star-ratings/js/dist/star-ratings.min.js' %}"></script> ... </html>
To enable ratings for a model add the following tag in your template
{% load ratings %} <html> ... {% ratings object %} ... </html>
Settings
To prohibit users from altering their ratings set STAR_RATINGS_RERATE = False in settings.py
To change the number of rating stars, set STAR_RATINGS_RANGE (defaults to 5)
Changing the star graphics
To change the star graphic, add a sprite sheet to /static/star-ratings/images/stars.png with the states aligned horizontally. The stars should be laid out in three states: full, empty and active.
Customize widget template
You can customize ratings widget by creating star_ratings/widget.html. For example :
{% extends "star_ratings/widget_base.html" %} {% block ratings_detail %} Whatever you want {% endblock %}
See star_ratings/widget_base.html for other blocks to be extended.
Ordering by ratings
The easiest way to order by ratings is to add a GenericRelation to the Rating model from your model:
class Foo(models.Model): bar = models.CharField(max_length=100) ratings = GenericRelation(Rating, related_query_name='foos') Foo.objects.filter(ratings__isnull=False).order_by('ratings__average')
Running tests
To run the test use:
$> ./runtests.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for django-star-ratings-0.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26ff16bc9336d730fa6574e3caa1bdead83fbd576e1cd28aa874c225d48b890f |
|
MD5 | 989bed25998a49aca62b54ed1563ac91 |
|
BLAKE2b-256 | ab9dc9dc02e09122c0b7b387b47c8e17c91d6bc0de3406254d33b8fe485f08a5 |
Hashes for django_star_ratings-0.5.0-py3.4.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08989da7aac0bcce09b293076258541db5345d686a02028e08854f93db520c0c |
|
MD5 | 71e6e1e81fe23e31d733e3f7ef051592 |
|
BLAKE2b-256 | 76d9f31a2949f46d26a50b8c2ddb2585314dd27578704244eacd357ac6fea771 |
Hashes for django_star_ratings-0.5.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a937a87d7ceda35255408c180806bc30002f8cdf73cc1a4329db19b24dc1ed65 |
|
MD5 | f3ddd5e1005496953a96434755b40759 |
|
BLAKE2b-256 | 38b7a4073ecde4ecceb757c06d5f15cd94e93fe46c3a0476a4000724cc439959 |