django-simple-ratings icondjango-simple-ratings 0.3.2

A simple, extensible rating system
django-simple-ratings is a simple and extensible rating system.

Getting started

you'd like to add ratings to some model:

from django.db import models
from rating.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()

>>> apple.ratings.average_score()

# 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):

The API is exactly the same.

last updated on:
August 30th, 2012, 11:37 GMT
developed by:
Charles Leifer
license type:
MIT/X Consortium License 
ROOT \ Internet \ HTTP (WWW)


In a hurry? Add it to your Download Basket!

user rating



Add your review!