'Updates or creates a rating for this item and user. Returns the rating'

def rate(self, item, user, value, flush=True):

    rating = self.rating(item, user, as_int=False)
    if (not rating):
        rating = self.rating_assoc(user=user)
        self.associate(rating, item)
    rating.rating = value
    self.session().add(rating)
    if flush:
        self.session().flush()
    return rating
