Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_top_actor():
- top_actor = (Actor.objects.prefetch_related('starring_actor_movies')
- .annotate(num_movies=Count('starring_actor_movies'),
- average_rating=Avg('starring_actor_movies__rating'))
- .order_by('-num_movies', 'full_name')).first()
- if not top_actor or top_actor.num_movies == 0:
- return ''
- all_movies = ', '.join(m.title for m in top_actor.starring_actor_movies.all())
- return (f"Top Actor: {top_actor.full_name}, starring in movies: {all_movies}, "
- f"movies average rating: {top_actor.average_rating:.1f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement