Wednesday, May 16, 2012

how to get count of ratings in the past 24hrs using django datetime?

I have a model name Ratings where there is a timestamp. I want to limit the user to only 3 ratings per day. how do I get a count of ratings for a particular user the past 24hrs?



class Ratings(models.Model):   
user = models.ForeignKey(User)
book = models.ForeignKey('Books')
rating = models.IntegerField(max_length=150)
timestamp = models.DateTimeField(auto_now_add=True)
is_checkedin_rating = models.BooleanField()


edit*
To be more clear, I want to find the count of ratings by a particular user in 24hrs. So from let's say 5/13 12AM to 5/14 12AM, get the count of ratings.





No comments:

Post a Comment