python - MongoAlchemy 嵌入文档

标签 python flask mongoalchemy

有谁知道如何使用 mongo alchemy 创建带有嵌入式文档的模型?我在文档中进行了搜索,但没有任何关于这样做的示例。

最佳答案

看看:

https://github.com/jeffjenkins/MongoAlchemy/blob/master/examples/examples.py

那里有一个示例,但为了完整性,是的 MongoAlchemy 可以使用这样的嵌入式文档:

class Address(Document):
    street_address = StringField()
    city = StringField()
    state_province = StringField()
    country = StringField()

class User(Document):

    name = StringField()
    email = StringField()

    address = DocumentField(Address)


user = User()
user.name = "tony"

user.address = Address()
user.address.city = "London"

关于python - MongoAlchemy 嵌入文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14492641/

相关文章:

python - MongoAlchemy StringField 意外替换为 QueryField?

python - Django - Unitest 还是 Doctest?

python - 属性错误 : 'Flask' object has no attribute 'user_options'

python - AttributeError: 'Element' 对象没有属性 'findAll'

python - Flask:如何构建与 HTML 下拉菜单交互的 POST 端点

python - Flask render_template 上下文在蓝图中为 None

python - MongoDB:将用户嵌入到评论中

python - 避免循环导入 Python

python - 有没有办法在 PySide 中设置 QtabWidget 上的选项卡按钮的样式?

python - 在 Python 中使用访问器的正确方法?