English 中文(简体)
外交部 主要模式没有管理人员(即:Foobject没有特性 foo_set )。
原标题:ForeignKey model has no Manager (i.e., Foo object has no attribute foo_set )

我在寻找答案,但找不到答案。 在使用外凯时,我始终看到一个错误,告诉我, F物体没有特性 f。 我是Django/Python的比喻,因此我确信这里有一个简单的答案,但我迄今未能找到答案。 这里有几部法典(储存各种委员会供游戏使用,其中每一部应当有与其相关的若干海因):

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)

确实会产生回报。

《刑法》(紧随上述法律,不工作):

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

“err”和“traceback.print_exc()”都提供:。 附录 rror: 标的委员会无属性委员会

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.

任何想法? 所有建议都受到赞赏。

最佳回答

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.

您将:

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

我认为,利用<代码>manage.py shell进行指挥和控制,以进口你的模型并检查这些模型(dir等),检查所有现有特性。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...