同じ構造型のインスタンスをその中に格納したいという点で「再帰的」なndbを使用して、GAEでデータ構造をモデル化しました。概念的には、
class Person(ndb.Model):
name = ndb.StringProperty()
friend = ndb.StructuredProperty(Person)
次のエラーが表示されます。
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 84, in LoadObject
obj = __import__(path[0])
File "C:\Users\Rusty\Documents\GitHub\AutoAddDrop\autoadddrop.py", line 2, in <module>
import models
File "C:\Users\Rusty\Documents\GitHub\AutoAddDrop\models.py", line 100, in <module>
class Bid(ndb.Model):
File "C:\Users\Rusty\Documents\GitHub\AutoAddDrop\models.py", line 123, in Bid
outbid_by = ndb.StructuredProperty(Bid) #Winning Bid
NameError: name 'Bid' is not defined
のクラスは次のmodels.py
とおりです。
class Bid(ndb.Model):
user_id = ndb.StringProperty()
league_id = ndb.StringProperty()
sport = ndb.StringProperty()
bid_amount = ndb.IntegerProperty()
timestamp = ndb.DateTimeProperty()
status = ndb.StringProperty()
target_player_id = ndb.StringProperty()
target_player_name = ndb.StringProperty()
target_player_team = ndb.StringProperty()
target_player_position = ndb.StringProperty()
add_player_id = ndb.StringProperty()
add_player_name = ndb.StringProperty()
add_player_team = ndb.StringProperty()
add_player_position = ndb.StringProperty()
drop_player_id = ndb.StringProperty()
drop_player_name = ndb.StringProperty()
drop_player_team = ndb.StringProperty()
drop_player_position = ndb.StringProperty()
bid_type = ndb.StringProperty()
bid_direction = ndb.StringProperty()
target_value = ndb.FloatProperty()
transaction_timestamp = ndb.DateTimeProperty()
outbid_by = ndb.StructuredProperty(Bid) #Winning Bid
outbid_by_key = ndb.KeyProperty(Bid) #key of winning bid
cbs_add_transaction = ndb.JsonProperty()
transaction_reason = ndb.StringProperty()