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
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 you 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.
Ordering by ratings
The easiest way to order by ratings is to add a GenericRelation to the AggregateRating model from your model:
class Foo(models.Model): bar = models.CharField(max_length=100) ratings = GenericRelation(AggregateRating, 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 Distribution
Hashes for django-star-ratings-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 636d7f559a37c78ebf11399760f9f8ae138e38cdb44d0411aee6242fb50b123b |
|
MD5 | 57ace7164d00bdee35a0d192493273f1 |
|
BLAKE2b-256 | 1e1e98194394db099c413b1b500f48625efb4210caff299cf498699a63cdae5d |
Hashes for django_star_ratings-0.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a93dd9d1a1846b55b62a7acb981371936c830b6dcb0fb2b13635ce45c7b5434a |
|
MD5 | a08fc4bee49b71b17d60d3c466be384d |
|
BLAKE2b-256 | 8747c8e70d34880db921f9965c5004a56092c339f546fc1a01555cdf3c472551 |