django-ratings

Generic Ratings in Django
Download

django-ratings Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • David Cramer
  • Publisher web site:
  • http://code.google.com/u/dcramer/

django-ratings Tags


django-ratings Description

Generic Ratings in Django django-ratings is a generic ratings module for the Django web framework. The field itself appends two additional fields on the model, for optimization reasons. It adds < field >_score, and < field >_votes fields, which are both integer fields.Installationsvn checkout http://django-ratings.googlecode.com/svn/trunk/ django-ratingscd django-ratingssudo python setup.py installYou will then need to add djangoratings to your INSTALLED_APPS:INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'djangoratings',)Finally, run python manage.py syncdb in your appication's directory to create the tables.Usagefrom djangoratings import RatingFieldRATING_CHOICES = ( (1, 'Up'), (-1, 'Down'),)class MyModel(models.Model): rating = RatingField(choices=RATING_CHOICES)Alternatively you could do something like:from djangoratings import AnonymousRatingFieldTEN_POINT_SCALE = class MyModel(models.Model): rating = AnonymousRatingField(choices=TEN_POINT_SCALE)And adding votes is also simple:myinstance.rating.add(score=1, user=request.user, ip_address=request.META)Retrieving votes is just as cake:myinstance_ai.get_rating(request.user, request.META)Accessing information about the rating of an object is also easy:# these do not hit the databasemyinstance.rating.votesmyinstance.rating.scorePotentially (not yet), you will also be able to query on the score and votes:(You cannot currently do this, instead us attname_score and attname_votes)MyModel.objects.filter(rating__score__gte=50).order_by('-rating__score') Requirements: · Django · Python


django-ratings Related Software