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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:17:27+00:00 2026-05-15T00:17:27+00:00

Does anyone have any clue why this doesn’t work as expected. If i use

  • 0

Does anyone have any clue why this doesn’t work as expected.

If i use the python shell and do

team.game_set

or

team.games

It returns an error

AttributeError: 'Team' object has no attribute 'game'

If i create a Game object and call

game.home_team

it returns the correct team object

Heres my model

class Team(models.Model):
    name = models.CharField(blank=True, max_length=100)

class Game(models.Model):
    home_team = models.ForeignKey(Team, related_name="home_team")

UPDATE

I’ve updated the mode by removing the related_name and i now get this error

app.game: Accessor for field 'home_team' clashes with related field 'Team.game_set'. Add a related_name argument to the definition for 'home_team'.
  • 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-15T00:17:28+00:00Added an answer on May 15, 2026 at 12:17 am

    Well, you set the related_name attribute. From the documentation:

    ForeignKey.related_name
    The name to use for the relation from the related object back to this one. See the related objects documentation for a full explanation and example. Note that you must set this value when defining relations on abstract models; and when you do so some special syntax is available.

    So if you want to have access to the objects via. team.game_set you have to remove this parameter:

    class Game(models.Model):
        home_team = models.ForeignKey(Team)
    

    or you access the games via the attribute home_team (but I guess you just misinterpreted the meaning of related_name):

    team.home_team
    

    If your class is going to have a guest_team attribute or multiple relationships to Team in general, you have to set a related name and might want to have something like this:

    class Game(models.Model):
        home_team = models.ForeignKey(Team, related_name="home_games")
        guest_team = models.ForeignKey(Team, related_name="guest_games")
    

    and then you can access the games via team.home_games and team.guest_games.

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

Sidebar

Related Questions

Does anyone have any clue as to what this might mean? (ClCompile target) ->
Does anyone have any examples on how to integrate a task scheduler in Bottle.
Does anyone have any idea how to change the thickness of the text pointer
DOes anyone have any good information with regards to when to log, I was
Does anyone have any tips that could help speed up a process of breaking
Does anyone have any useful advice/links to information about working with mp3 files in
Does anyone have any advice or techniques for deploying SSIS packages to the Integration
Does anyone have any experience querying FlexLM? (At a minimum) I need to be
Does anyone have any advice on which method is better when caching data in
Does anyone have any recommendations of resources for learning ASP.NET specifically? I have a

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.