小编Fré*_*ade的帖子

在Flask-Admin中处理MongoEngine的DynamicEmbeddedDocument

我有一个问题,我找不到一个简单的解决方案,使用Flask-Admin和MongoEngine.我有一个名为的Document类ExerciseResourceContent.它有一个"问题"属性,它是一个ListField一个的EmbeddedDocumentExerciseQuestion:

class ExerciseResourceContent(ResourceContent):
    """An exercise with a list of questions."""

    ## Embedded list of questions
    questions = db.ListField(db.EmbeddedDocumentField(ExerciseQuestion))
Run Code Online (Sandbox Code Playgroud)

ExerciseQuestion文件实际上是DynamicEmbeddedDocument:

class ExerciseQuestion(db.DynamicEmbeddedDocument):
    """
    Generic collection, every question type will inherit from this.
    Subclasses should override method "without_correct_answer" in order to define the version sent to clients.
    Subclasses of questions depending on presentation parameters should also override method "with_computed_correct_answer".
    """

    _id = db.ObjectIdField(default=ObjectId)

    ## Question text
    question_text = db.StringField(required=True)

    ## …
Run Code Online (Sandbox Code Playgroud)

python mongoengine flask flask-admin

16
推荐指数
1
解决办法
789
查看次数

标签 统计

flask ×1

flask-admin ×1

mongoengine ×1

python ×1