Monday, April 29, 2013

Little help needed writing models for star-ratings app

Here is the story so far

class Rating(models.Model):
positive_rating = models.FloatField(default=0)
negative_rating = models.FloatField(default=0)

class Book(models.Model):
year_pub = models.IntegerField(max_length=4)
category = models.ForeignKey(Category)
rating = models.ForeignKey(Rating)
hash_id = models.CharField(max_length=64, null=True, blank=True)

There are few books. Each will be having 2 types of rating. +ve one and -ve one, 
The rating is done using "stars". If +ve rating is done, -ve field will be 0 vice versa.

votes could be simple stored in this way

o = Book.objects.get(pk=1)
o.rating.positive_rating += 2.5

Here comes the actual trouble -->

1. How to count the number of ratings
2. How to know which user has voted
3. How to know whether the user has previously voted or not

Typically, how to attach this MyUser (example) model to the Rating Model?


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment