Wils221 / raterproject-server

0 stars 0 forks source link

Adding average rating of game #11

Open AmyUlmer opened 1 year ago

AmyUlmer commented 1 year ago

using custom property on game model

@property

def average_rating(self):

    """Average rating calculated attribute for each game"""

    ratings = self.ratings.all()

    # Sum all of the ratings for the game

    total_rating = 0

    for rating in ratings:

        total_rating += rating.rating

    if len(ratings) != 0:

        avg = total_rating / len(ratings)

    else:

        avg = 0

    # Calculate the averge and return it.

    return avg
AmyUlmer commented 1 year ago

rate #13