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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:02:01+00:00 2026-05-30T04:02:01+00:00

I have this chunk of code which adds up all the players hurt on

  • 0

I have this chunk of code which adds up all the players hurt on one team.

teams = Team.objects.annotate(team_count=Count('Team played for')).order_by('city')

I am having an issue however. It is currently adding all injuries, but I would like to count just the players that are currently injured, or more specifically… where returned=False

Here are my models for a bit more context.

Team models.py

class Team(models.Model):
    city = models.CharField(verbose_name='City', max_length=30, null=True, blank=True)
    team_name =  models.CharField(verbose_name='Team Name', max_length=30, null=True, blank=True)
    team_logo = models.ImageField(upload_to='images/', null=True, blank=True)
    team_affiliation = models.ForeignKey('self', null=True, blank=True)

    def __unicode__(self):
        return u'%s %s' % (self.city, self.team_name)

EDIT added player models.py

class Player(models.Model):
    first_name = models.CharField(verbose_name='First Name', max_length=30, null=True, blank=True)
    last_name = models.CharField(verbose_name='Last Name', max_length=30, null=True, blank=True)
    team = models.ForeignKey(Team, related_name='Team played for')
    position = models.ForeignKey(Position, related_name="Position")
    pob = models.CharField(verbose_name='Place of Birth', max_length=100, null=True, blank=True)
    dob = models.DateField()
    age =  models.IntegerField(null=True, blank=True)
    height = models.CharField(verbose_name='Height', max_length=10, null=True, blank=True)
    weight = models.CharField(verbose_name='Weight', max_length=10, null=True, blank=True)
    drafted_by = models.ForeignKey(Team, related_name='drafted by', null=True, blank=True)

    def __unicode__(self):
        return u'%s %s' % (self.first_name, self.last_name)

Injury models.py

class PlayerInjury(models.Model):
    player =  models.ForeignKey(Player)
    injury_type = models.ForeignKey(Injury)
    injury_date = models.DateField(verbose_name='Injured On', null=True, blank=True)
    description = models.CharField(verbose_name='Description', max_length=180, null=True, blank=True)
    status = models.ForeignKey(Status)
    projected_return = models.DateField(verbose_name='Projected Return Date', null=True, blank=True)
    hide = models.BooleanField(default=False)
    returned = models.BooleanField(default=False)
    timestamp = models.DateTimeField(auto_now_add=True)
    source = models.URLField(max_length=200, null=True, blank=True)
    source_label = models.CharField(null=True, blank=True, max_length=200)

    def __unicode__(self):
        return u'%s - %s' % (self.player, self.injury_type)

Is there a way I can filter the annotation so that it will only count the currently injured players?

  • 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-30T04:02:02+00:00Added an answer on May 30, 2026 at 4:02 am

    Just filter before calling annotate: .filter(player__playerinjury__returned=False).annotate(...).

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

Sidebar

Related Questions

I have this chunk of code which I found and implemented according to http://www.activexperts.com/activmonitor/windowsmanagement/scripts/networking/windowsfirewall/
I have this chunk of code which is placed in accelerometer: didAccelerate which changes
If I have a chunk of code like this: .hover( function () { hoverState($(#navbar
I have a chunk of java code which hard codes a hibernate disjunction query
I have a piece of C code which with a chunk of memory(static array)
In my project I have two chunk of code which I would like to
I have this chunk of code in an R script, and what it does
I have this code snippet: val chunks = blob.map(_.id).distinct.grouped(100).toSeq val output = (for (chunk
I have this code here, which get a plain text, and turns it to
I have this structure which i am trying to initialize using the following code.

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.