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

  • SEARCH
  • Home
  • 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 7953713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:13:28+00:00 2026-06-04T03:13:28+00:00

I have these models: class Assignment(db.Model): title = db.StringPeoperty(required=True) …other stuff… class TeamScore(db.Model): assignment

  • 0

I have these models:

class Assignment(db.Model):
    title = db.StringPeoperty(required=True)
    ...other stuff...

class TeamScore(db.Model):
    assignment = db.ReferenceProperty(Assignment, 
                                      collection_name="teamScores",
                                      required=True)
    teamID = db.IntegerProperty(required = True)
    score = db.IntegerProperty(required = True)
    ...other stuff...

Here is the peoblem. In the homepage, I want to show the top three( based on score) team work of each assignment. So, I pass this to my template:

assignments = Assignment.all()

In the template:

{% for assignment in assignments%}
    **<!--How to implement showing the top three-->**
    {% for score in assignment.teamScores%}
         {{score.teamID}}
         {{score.score}}
         ...............
    {% endfor%}
{%endfor%}

With this datastore model. I need to sort in template, it’s impossible. So, I think it may have a better model to handle this problem. But I can’t figure it out. I thought about this idea that add a ListProperty to store the top three. Everytime a new TeamScore generated, I will compare this to the scores in the List to keep the top three fresh. But I think this way is not elengance.

Can you give me some suggestion?

Thank you!

  • 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-04T03:13:30+00:00Added an answer on June 4, 2026 at 3:13 am

    This isn’t a data modelling issue, it’s a templating one. You need to fetch the assignments and perform the queries to get the list of scores in your code, and pass the results into the template, rather than just passing in the assignment model and doing the rest of the work in your template.

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

Sidebar

Related Questions

I have these models: class Gallery(models.Model): HeadImage = models.ImageField(upload_to=gallery,blank=True,null=True) class News(Gallery): Name=models.CharField(max_length=100) #some other
I have these models set up in Django: class SourceBusiness(models.Model): source = models.CharField(max_length=100) ...(other
I have these models: class Projects(models.Model): projectName =models.CharField(max_length = 100,unique=True,db_index=True) projectManager = EmbeddedModelField('Users') class
I have these two models : class Module(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(unique=True,
I have these models: class Model1(models.Model): ... class Model2(models.Model): m1 = models.OneToOneField(Model1, related_name='m2') ...
I have these models: class UserProfile(models.Model): user = models.OneToOneField(User) #etc class Organization(models.Model): users =
Let's say I have these models: class A(models.Model): name = models.CharField(max_length=32) b = models.ForeignKey(B,
I have these models: class Client(models.Model): is_provider = models.BooleanField() class Billing(models.Model): client = models.ForeignKey(Client)
say I have these models: class Parent(models.Model): slug = models.SlugField() class Child(models.Model): slug =
I have these two models: class CommonVehicle(models.Model): year = models.ForeignKey(Year) series = models.ForeignKey(Series) engine

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.