10
我不知道這是否是內MongoEngine或者如果我錯過了什麼的錯誤。 我有以下型號設置:MongoEngine ListField引發TypeError上驗證
class Features(EmbeddedDocument):
version = FloatField()
data = ListField(StringField)
class Article(Document):
vendor = ReferenceField(Vendor)
url = URLField()
author = StringField()
clean_content = StringField()
features = EmbeddedDocumentField(Features)
當我測試的模型是這樣的:
#add vendor
vendor = Vendor(name="techcrunch", config="vendor config")
vendor.save()
#create features
features = Features(version = 1.0)
features.data = ["5", "89"]
#add article
article = Article(vendor = vendor, url ="http://www.techcrunch.com",
author ="MG Siegler", clean_content = "Apple rocks!")
article.features = features
article.save()
我得到以下錯誤:
TypeError: unbound method _validate() must be called with StringField instance as first argument (got str instance instead)
有人能解釋一下嗎?
編輯:
沒關係。我發現我的錯誤。
它必須是:
class Features(EmbeddedDocument):
version = FloatField()
data = ListField(StringField())
你應該張貼您的答案和標記問題的回答! – Ross
我忘了。謝謝。 – Karsten