Closed FilipVyrostko closed 3 years ago
ugh why it made my comment a title
Ok, I will add the first two. The producer is already referenced with a foreign key though, I don't see why a separate producer object is necessary
also need to add this
average_rating = models.IntegerField(default=0)
num_of_ratings = models.IntegerField(default=0)
Oh yeah did not notice the producer sorry
I'm not sure if adding these fields is a good idea. I believe it is a better approach to obtain these values with the following query:
movies = Movie.objects.annotate(avg_rating=Avg('rating__rating').annotate(num_ratings=Count('rating')
Now, movies is a list with all stored movies with the added attributes avg_rating and num_ratings, which can be accessed in the following way:
movies[i].num_ratings
and movies[i].avg_rating
.
Finally, this list can be sorted by the new avg_rating attribute as follows:
movies.order_by('-avg_rating')
Oh thats cool, I did not know about this. I will use this then
I think we need 3 more tables in the database for movie model. This is the code;
Cover picture for the movie