У меня есть проблема, для которой я не могу найти простое решение, используя Flask-Admin с MongoEngine.
У меня есть класс Document с именем ExerciseResourceContent
. Он имеет атрибут "вопросы", который является ListField
EmbeddedDocument
, называемым ExerciseQuestion
:
class ExerciseResourceContent(ResourceContent):
"""An exercise with a list of questions."""
## Embedded list of questions
questions = db.ListField(db.EmbeddedDocumentField(ExerciseQuestion))
Документ 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)
## Correct answer (field type depends on question type)
correct_answer = db.DynamicField()
Он может быть подклассифицирован в двух классах (еще впереди): MultipleAnswerMCQExerciseQuestion и UniqueAnswerMCQExerciseQuestion:
class MultipleAnswerMCQExerciseQuestion(ExerciseQuestion):
"""Multiple choice question with several possible answers."""
## Propositions
propositions = db.ListField(db.EmbeddedDocumentField(MultipleAnswerMCQExerciseQuestionProposition))
## Correct answer
correct_answer = db.ListField(db.ObjectIdField())
class UniqueAnswerMCQExerciseQuestion(ExerciseQuestion):
"""Multiple choice question with one possible answer only."""
## Propositions
propositions = db.ListField(db.EmbeddedDocumentField(UniqueAnswerMCQExerciseQuestionProposition))
## Correct answer
correct_answer = db.ObjectIdField()
Когда я использую Flask-Admin для создания или редактирования ExerciseResourceContent
, он отображает список "Вопрос", из которого я могу редактировать атрибут "Question_text", но я не вижу атрибута "Correct_Answer", Атрибут "Предложения", как и я.
Я боролся с документом Flask-Admin, но, похоже, проблема с динамическим материалом (полями или документами), и в документах ничего нет.
Спасибо за помощь