'Django: How to display the average of all rating using django?

i am creating a function where users can rate a book using django, i have achieved the part where users can rate the book using a form from the front end and it get saved in the backend. Now what i want to achieve is a way to display an average of all the rating that the user make. e.g let say there are usera - 1.0, userb - 3.0, userc -5.0. i want to display the average which is 3.0 and i dont know how to achive this. let men put some of the code i have written below

models.py

USER_BOOK_RATING = (
        ("1.0", "★☆☆☆☆ (1/5)"),
        ("2.0", "★★☆☆☆ (2/5)"),
        ("3.0", "★★★☆☆ (3/5)"),
        ("4.0", "★★★★☆ (4/5)"),
        ("5.0", "★★★★★ (5/5)"),
)

class BookRating(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    book = models.ForeignKey(Book, on_delete=models.CASCADE, null=True)
    rating = models.CharField(max_length=1000, choices=USER_BOOK_RATING)
    review = models.TextField()

view.py - only what i am doing is listing out all the reviews but not the average of star rating



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source