我尝试在 Flask 中模拟我的 MongoAlchemy 课程。这是我的模型:
{
"_id" : ObjectId("adfafdasfafag24t24t"),
"name" : "sth."
"surname" : "sth."
"address" : [
{
"city" : "Dublin"
"country" : "Ireland"
}
]
}
这是我的documents.py类:
class Language_School(db.Document):
name = db.StringField()
surname = db.StringField()
address = db.???
如何在 Flask 中定义类似数组模型(地址)?
编辑:在提问之前,我已经尝试过我的模型。但我犯了像“AttributeError AttributeError:'list'对象没有属性'items'”这样的错误。
class Address(db.Document):
city = db.StringField()
country = db.StringField()
class Language_School(db.Document):
name = db.StringField()
surname = db.StringField()
address = db.DocumentField(Address)