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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:08:44+00:00 2026-05-23T11:08:44+00:00

Why does the following return no results: >>> count = PlayerYear.objects.filter(team__id=3128).count() >>> count #

  • 0

Why does the following return no results:

>>> count = PlayerYear.objects.filter(team__id=3128).count()
>>> count # Output: 0

But this returns 32 (the number of players this year on the Admiral Farragut Academy Football team):

>>> count = PlayerYear.objects.filter(team__id=1).count()
>>> count # Output: 32

Given the following table (teams_team):

---------------------------------------------------------
|  id  | school_id |       admin_display                |
---------------------------------------------------------
| 3128 |     1     | Admiral Farragut Academy: Football |

And the following (abbreviated) models:

class PlayerYear(models.Model):
    player = models.ForeignKey(Player)
    team = models.ForeignKey(Team)
    # snip

and

class Team(models.Model):
    legacy_id = models.IntegerField(blank=True, null=True)
    school = models.ForeignKey(School)
    # snip

and

class School(models.model):
    legacy_id = models.IntegerField(blank=True, null=True)
    school = models.CharField(max_length=255, blank=True, null=True)
    # snip

I do not understand why I get results when providing the school_id value, even though I specified team__id as the filter. How can I get results using the Team ID (3128)?

  • 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-23T11:08:44+00:00Added an answer on May 23, 2026 at 11:08 am

    Looking at your models it looks like you should be using legacy_id in your query rather than id:

    count = PlayerYear.objects.filter(team__legacy_id=3128).count()
    

    (Note: It appears that you have both a primary id field, and a legacy_id field in your database. You actually don’t need to set ID fields manually in your models, since Django automatically does this for you. From the docs: If you don't specify primary_key=True for any fields in your model, Django will automatically add an IntegerField to hold the primary key, so you don't need to set primary_key=True on any of your fields unless you want to override the default primary-key behavior.

    https://docs.djangoproject.com/en/dev/topics/db/models/

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

Sidebar

Related Questions

What does the following expression return in Java? Math.max(Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); I saw this question
In Python compiled regex patterns have a findall method that does the following: Return
Why does the following query return 'zero' records: SELECT * FROM records WHERE rownum
I'm getting crazy with this IE 7... ==> hhttp://neu.emergent-innovation.com/ Why does following function not
LINQ drives me crazy. Why does following query not return the duplicates, whereas it
does the following integer arithmetic property hold? (m/n)/l == m/(n*l) At first I thought
The following does not compile, and I cannot for the life of me see
The following does not compile: class Foo { public: Foo( boost::shared_ptr< Bar > arg
Why does the following code sometimes causes an Exception with the contents CLIPBRD_E_CANT_OPEN: Clipboard.SetText(str);
Why does the following code not work as I was expecting? <?php $data =

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.