0
如何創建兩個不同實體模型之間的關係?GAE(Python)在ndb中定義實體關係
當我嘗試這個,我得到一個錯誤:
class Spec(ndb.Model):
userKey = ndb.KeyProperty(kind=User)
class User(ndb.Model):
specs = ndb.KeyProperty(kind=Spec, repeated=True)
按我的理解,從定義之前引用用戶莖的錯誤。 我做了以下解決它,我用一個get_by_id,但我不喜歡這樣的解決方案:
class Spec(ndb.Model):
userKey = ndb.IntegerProperty()
class User(ndb.Model):
specs = ndb.KeyProperty(kind=Spec, repeated=True)
你會如何解決這個問題,所以我可以定義我的模型作爲第一個例子?更好的是,你將如何去定義每個類在它自己的文件/模塊中。
我試過了這篇文章,但它似乎已經過時了,並且與ndb無關。 https://developers.google.com/appengine/articles/modeling
謝謝