Open HuxleyBerry opened 16 hours ago
On second thoughts, for performance reasons, rather than using order_by()
, it may be better to change the ordering
field in the Meta
class of the user model so that the users are ordered automatically by their total score. See https://docs.djangoproject.com/en/5.1/ref/models/options/#django.db.models.Options.ordering.
Another possibility for improving performance is caching, but we can worry about that later (outside the scope of this issue).
Prerequisites
3
Issue
Make an API view which retrieves the top twenty (maybe subject to change) users according to their total points. It just needs to retrieve the name, rank, and points of each of those ten users (in order). You can use Django's
order_by()
method for this: https://docs.djangoproject.com/en/5.1/ref/models/querysets/#order-by.Users with the same number of points should be given the same rank, so you'll have to do a bit more work than just using
order_by
.Additionally, the view should return the rank of the currently logged in user, since we'll also want to display that on the leaderboard page even if they aren't in the top twenty.