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
using custom property on game model
@property