I have been creating a website for a donation service. We currently have a leaderboard that displays all of the users, how many times they have donated, and how many donations they have made. Let's start simple, I need the results to show in descending order so that the highest number is atop the leaderboard.
Here is my models.py
with my get_queryset()
.
class UserListView(ListView):
model = User
template_name = 'leaderboards.html'
def get_queryset(self):
queryset = super(UserListView, self).get_queryset()
return queryset.annotate(
contributions_count=Count('contribution'),
contributions_total=Sum('contribution__amount'),
)
Now I also need a leaderboard exactly like the last but with just the monthly donation leaders.
Any help would be much appreciated.
Edit: Here is my model for Contribution. The amount
field is the one that I am concerned with. The date I would like to use is the date it was posted.
class Contribution(models.Model):
amount = models.IntegerField()
date = models.DateField(auto_now_add=True)
notes = models.CharField(max_length=50)
user = models.ForeignKey(User)