Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 694203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:49:57+00:00 2026-05-14T02:49:57+00:00

First of all, sorry if this isn’t an appropriate question for StackOverflow. I’ve tried

  • 0

First of all, sorry if this isn’t an appropriate question for StackOverflow. I’ve tried to make it as generalisable as possible.

I want to create a database (MySQL, site running Django) that has users, who can be allocated a certain number of points for various types of action – it’s a collaborative game. My requirements are to obtain:

  • the number of points a user has
  • the user’s ranking compared to all other users
  • and the overall leaderboard (i.e. all users ranked in order of points)

This is what I have so far, in my Django models.py file:

class SiteUser(models.Model):
    name = models.CharField(max_length=250 )
    email = models.EmailField(max_length=250 )
    date_added = models.DateTimeField(auto_now_add=True) 
    def points_total(self):
        points_added = PointsAdded.objects.filter(user=self)
        points_total = 0
        for point in points_added:
            points_total += point.points
        return points_total

class PointsAdded(models.Model):
    user = models.ForeignKey('SiteUser')
    action = models.ForeignKey('Action')
    date_added = models.DateTimeField(auto_now_add=True) 
    def points(self):
        points = Action.objects.filter(action=self.action)
        return points

class Action(models.Model):
    points = models.IntegerField()
    action = models.CharField(max_length=36)

However it’s rapidly becoming clear to me that it’s actually quite complex (in Django query terms at least) to figure out the user’s ranking and return the leaderboard of users. At least, I’m finding it tough. Is there a more elegant way to do something like this?

This question seems to suggest that I shouldn’t even have a separate points table – what do people think? It feels more robust to have separate tables, but I don’t have much experience of database design.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:49:58+00:00Added an answer on May 14, 2026 at 2:49 am

    It’s a bit more difficult to have points saved in the same table, but it’s totally worth it. You can do very simple ordering/filtering operations if you have computed points total on user model. And you can count totals only when something changes (not every time you want to show them). Just put some validation logic into post_save signals and make sure to cover this logic with tests and you’re good.

    p.s. denormalization on wiki.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, sorry if this question is a little vague and rambling! I'm
First of all I'm sorry if you feel this question has been raised before,
First of all, sorry to post a question like this when so many other
First of all sorry, If somebody finds this question is repeated (haven't found any
First of all there is a partial question regarding this, but it is not
All, Sorry - this is probably a very strange question. I'm working on a
First, sorry this is so long. I probably don't need all the code, but
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
First, sorry for my English, im not an American. My question is how can
First of all, sorry about the title -- I couldn't figure out one that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.