def update(postid, userid, rating): uu = TabRating.select().where((TabRating.post_id == postid) & (TabRating.user_id == userid)) if uu.count() > 0: MRating.__update_rating(uu.get().uid, rating) else: MRating.__insert_data(postid, userid, rating)
def get_rating(postid, userid): try: uu = TabRating.select().where((TabRating.post_id == postid) & (TabRating.user_id == userid)) except: return False if uu.count() > 0: return uu.get().rating else: return False
def update(postid, userid, rating): ''' Update the rating of certain post and user. The record will be created if no record exists. ''' rating_recs = TabRating.select().where((TabRating.post_id == postid) & (TabRating.user_id == userid)) if rating_recs.count() > 0: MRating.__update_rating(rating_recs.get().uid, rating) else: MRating.__insert_data(postid, userid, rating)
def get_rating(postid, userid): ''' Get the rating of certain post and user. ''' try: recs = TabRating.select().where((TabRating.post_id == postid) & (TabRating.user_id == userid)) except: return False if recs.count() > 0: return recs.get().rating else: return False
def query_average_rating(postid, limit=1000): return TabRating.select( peewee.fn.Avg(TabRating.rating).over( order_by=[TabRating.timestamp.desc()])).where( TabRating.post_id == postid).limit(limit).scalar()
def query_by_post(postid, limit=20): return TabRating.select().where( TabRating.post_id == postid).limit(limit)