a simple, extensible rating system.
Project description
a simple, extensible rating system.
dependencies:
django-generic-aggregation: http://github.com/coleifer/django-generic-aggregation
With a little bit more
also, a playground for different stuff i’ve been reading about in programming collective intelligence, by toby segaran.
this stuff lives in utils.py and is there if you want to experiment (or contribute!).
Getting started
you’d like to add ratings to some model:
from django.db import models from ratings.models import Ratings class Food(models.Model): name = models.CharField(max_length=50) ratings = Ratings()
now, you can:
# add ratings to things >>> apple.ratings.rate(user=john, score=1) <RatedItem: apple rated 1 by john> >>> apple.ratings.rate(user=jane, score=5) <RatedItem: apple rated 5 by jane> # get interesting aggregate data >>> apple.ratings.all() [<RatedItem: apple rated 1 by john>, <RatedItem: apple rated 5 by jane>] >>> apple.ratings.cumulative_score() 6 >>> apple.ratings.average_score() 3.0 # order things by their rating >>> Food.ratings.order_by_rating() [<Food: apple>, <Food: orange>]
Use GFKs, FKs, whatever
By default, whenever you add Ratings() to your model it uses the RatedItem model which has a GFK on it. Suppose you are only rating one thing, or would like to have an explicit database constraint – that’s no problem. You can provide a custom RatedItem model with a ForeignKey instead of a GFK. Here’s the example from the tests:
class BeverageRating(RatedItemBase): content_object = models.ForeignKey('Beverage') class Beverage(models.Model): name = models.CharField(max_length=50) ratings = Ratings(BeverageRating) def __unicode__(self): return self.name
The API is exactly the same.
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
Built Distribution
File details
Details for the file django-simple-ratings-0.3.3.tar.gz
.
File metadata
- Download URL: django-simple-ratings-0.3.3.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14cdd23703edfb099fb3c6ec6b488a1e5025b770cd6fe0b6b5aa0fc98f2ca053 |
|
MD5 | 775717d41e6bbb44aa9a49faf18490a0 |
|
BLAKE2b-256 | 4d2a87e5dc7af91b37c48c98fda306c01aaf558f66d909d6d19aae70c97b054f |
File details
Details for the file django_simple_ratings-0.3.3-py2.py3-none-any.whl
.
File metadata
- Download URL: django_simple_ratings-0.3.3-py2.py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40580269c15bcf37af051fe554c250dded484d8f566e0a69cff73f0b2b5d422f |
|
MD5 | 9625f47a60abe1f89ecf39da4f489883 |
|
BLAKE2b-256 | f9bc9c976afeb684e5ed4b6a663181abbd7336dde62d4cb95613e4f647f93052 |