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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:57:12+00:00 2026-05-20T10:57:12+00:00

I have searched around for an answer to this but can’t find one. When

  • 0

I have searched around for an answer to this but can’t find one. When using a ForeignKey, I am consistently getting an error telling me that ‘Foo object has no attribute ‘foo_set’. I am a bit new to Django/Python, so I’m sure there is a simple answer here, but I haven’t been able to find it so far. Here’s some code (to store varied Boards for use in a game, each of which should have a number of Hexes associated with it):

Models:

class Boards(models.Model):
  boardnum = models.IntegerField(unique=True)
  boardsize = models.IntegerField(default=11)
  hexside = models.IntegerField(default=25)
  datecreated = models.DateTimeField(auto_now_add = True)

class Hexes(models.Model):
  boardnum = models.ForeignKey(Boards, null = True)
  col = models.IntegerField()
  row = models.IntegerField()
  cost = models.IntegerField(default=1)

Code (this works):

newboard, createb = Boards.objects.get_or_create(boardnum=boardn)

createb returns True.

Code (this immediately follows the above, and does not work):

try:
  hx = newboard.boards_set.create(col=c, row=r)
except Exception, err:
  print "error:", err
  traceback.print_exc()

Both “err” and “traceback.print_exc()” give: AttributeError: ‘Boards’ object has no attribute ‘boards_set’

I get the same error if I first create the Hexes record with a get_or_create and then try a newboard.boards_set.add() on it.

Any ideas? All suggestions appreciated.

  • 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-20T10:57:13+00:00Added an answer on May 20, 2026 at 10:57 am

    The name that Django uses for a reverse foreign key manager is the name of the model that contains the foreign key, not the name of the model that the manager is on.

    In your case, it will be:

    newboard.hexes_set.create(col=c,row=r)
    

    I find it useful to use the manage.py shell command to import your models and inspect them (with dir, etc) to check out all the available attributes.

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

Sidebar

Related Questions

I have searched around but can't find the answer to this relatively simple question;
I've searched around the net but can't seem to find quite the answer to
I have searched the site, but can not find the answer or how it
I searched around but couldn't find an answer. I'm not sure if this is
I've searched around for this, but cannot find a direct answer so here it
I've searched for this but can't seem to find a straight answer for this.
I have searched around Google and StackOverflow trying to find a solution to this,
I searched around but couldn't find exactly what I'm looking for. I have a
I have searched for a general solution to this but only find answers to
I searched, but surprisingly couldn't find an answer. I have a long NSString that

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.