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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-star-ratings-0.2.0.tar.gz.
File metadata
- Download URL: django-star-ratings-0.2.0.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d77479874b5a5152e5a3e5a19335f5adc837fd7e0468937f2bedc339330307f
|
|
| MD5 |
848892028f0cf8248cdf6f64131fb4cb
|
|
| BLAKE2b-256 |
129ac24bb39b6c950758f9fbfbb26378b47b4228818fd008fff82611353eda86
|
File details
Details for the file django_star_ratings-0.2.0-py2.py3-none-any.whl.
File metadata
- Download URL: django_star_ratings-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.1 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65a46198772708490e5b80ade82a16786d8a1111dc5fd6f8ebd4f9d6ec571dd8
|
|
| MD5 |
8e2966f16c08acc701295891f23da208
|
|
| BLAKE2b-256 |
a24eaa2182a47d589fe7efa9b6b0ecf4f1db6fe4c84bcfbcbca9c587bea5562e
|