Add single extra field in a paginated response in drf

I've a monthly quiz website. The quiz attempt model is something like this:

class UserAttempts(models.Model):
    user = FK(User)
    quiz = FK(Quiz)
    answer = FK(Answer)
    points_earned = IntegerField

Now I'm ranking each user for every month based on their total points earned. I'm using this query to achieve this task:

UserAttempts.objects.filter(quiz__start_date__month=date.today().month
                ).values('user').annotate(correct_answer=Count('answer__is_correct')
                ).annotate(rank=Window(expression=DenseRank(), order_by= 
               [F('correct_answer').desc(),]))

I'm sending the paginated response of the monthly rankings of user with their names, id's and number of correct and incorrect answers. Now I want to add the previous month rank of the current logged in user in my paginated response so that I can show his progress against his last month rank when he's fetching the total user rank table.

I'm using generics.ListAPIView in drf. How can I achieve this?

Back to Top