django-simple-ratings 0.3.3

a simple, extensible rating system.

a simple, extensible rating system.

dependencies:

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.

Author

Deutscher Django Verein e. V.

Pip

django-simple-ratings==0.3.3

Classifiers

  • Programming Language :: Python
  • Operating System :: OS Independent
  • License :: OSI Approved :: MIT License
  • Intended Audience :: Developers
  • Framework :: Django
  • Environment :: Web Environment
  • Development Status :: 4 - Beta
File Type Python Version Uploaded On Downloads
django_simple_ratings-0.3.3-py2.py3-none-any.whl Wheel py2.py3 Nov. 28, 2013 1,007
django-simple-ratings-0.3.3.tar.gz Source Nov. 28, 2013 1,344
Version Release Date
0.3.3 Nov. 28, 2013
0.3.2 Aug. 27, 2012
0.3.0 July 13, 2011
0.2.0 March 16, 2011
0.1.2 Oct. 19, 2010
0.1.1 Sept. 25, 2010
0.1.0 Aug. 8, 2010
Date Package Version Action
Nov. 4, 2014, 1:49 p.m. django-simple-ratings 0.1.2 Release Created
Nov. 4, 2014, 1:49 p.m. django-simple-ratings 0.1.1 Release Created
Nov. 4, 2014, 1:49 p.m. django-simple-ratings 0.1.0 Release Created
Nov. 4, 2014, 1:49 p.m. django-simple-ratings 0.2.0 Release Created
Nov. 4, 2014, 1:49 p.m. django-simple-ratings 0.3.0 Release Created
Nov. 4, 2014, 1:49 p.m. django-simple-ratings 0.3.3 Release Created
Nov. 4, 2014, 1:49 p.m. django-simple-ratings 0.3.2 Release Created
Nov. 4, 2014, 1:49 p.m. django-simple-ratings Package Created