11

我不确定这是 MongoEngine 中的错误还是我错过了什么。我设置了以下模型:

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())
4

1 回答 1

15

我发现了错误。

它一定要是:

class Features(EmbeddedDocument):
    version = FloatField()
    data = ListField(StringField())
于 2012-09-19T22:34:15.367 回答