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 9039643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:46:47+00:00 2026-06-16T09:46:47+00:00

When I list points I want to add up all the points for a

  • 0

When I list points I want to add up all the points for a user. In my template I’ll like to just call something like ‘points.total_points’. Below is what I have so far, I would like to keep this all in my model if possible. Could someone help explain how to acheive this?

Thanks

model.py

class PointsManager(models.Manager):

    def points_list(self,thisUser):
        list = Points.objects.filter(user=thisUser)
        return list


class Points (models.Model):
    user = models.ForeignKey(User)
    points = models.IntegerField(verbose_name=("Points"), default=0)
    created = models.DateTimeField(("Created at"), auto_now_add=True)
    updated = models.DateTimeField(verbose_name=("Updated at"), auto_now=True)

    objects = PointsManager()



    class Meta:
      verbose_name = ('Point')
      verbose_name_plural = ('Points')

view.py

@login_required
def history(request):

    thisPoints = Points.objects.points_list(request.user)
    context = {'points':thisPoints}
    return render_to_response('points/history.html', context, context_instance=RequestContext(request))
  • 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-06-16T09:46:48+00:00Added an answer on June 16, 2026 at 9:46 am

    There’re a couple of things that could be done:

    1) make request available in templates:

    add common.core.middleware.RequestMiddleware to MIDDLEWARE_CLASSES

    so that you could just write request.user to access User model

    2) add total_points method to User model (it can be done in various ways, contribute_to_class or UserProfile to name two of them)

    so that you could write request.user.total_points in a template

    3) cache total_points to avoid a database hit every time the page is viewed:

        3a) either use standard django caching framework,

    or if you want the displayed value to change immediately after it has been changed in the database,

        3b) update the value manually when a new Point instance is created/modified/deleted via django signals

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

Sidebar

Related Questions

I have a list of data points (0.2, 0.8, 0.95) that I want to
I have a list of points as shown below points=[ [x0,y0,v0], [x1,y1,v1], [x2,y2,v2].......... [xn,yn,vn]]
I have the following URL: http://localhost:8000/store/add/?points=5 I want to extract the number of points
I want to create a GraphicsPath and a list of Points to form the
I want to plot several lists of points, each list has distance (decimal) and
I have a list of points moving in two dimensions ( x - and
I have a SharePoint external list that points to a 100,000 record SQL table.
I have two polygons which are defined by a list of points: x1,y1; x2,y2;
I have a ViewModel class that contains a list of points, and I am
I would like to get some information on list of points that needs to

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.