I have a problem for which I can't find a simple solution, using Flask-Admin with MongoEngine.
I have a Document class named ExerciseResourceContent
. It has a "questions" attribute, which is a ListField
of an EmbeddedDocument
called ExerciseQuestion
:
class ExerciseResourceContent(ResourceContent):
"""An exercise with a list of questions."""
## Embedded list of questions
questions = db.ListField(db.EmbeddedDocumentField(ExerciseQuestion))
The ExerciseQuestion
document is actually a 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()
It can be subclassed in two classes (more to come): MultipleAnswerMCQExerciseQuestion and 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()
When I use Flask-Admin to create or edit an ExerciseResourceContent
, it displays a "Question" list, from which I can edit a "Question_text" attribute, but I can't see "Correct_Answer" attribute, nor any "Propositions" attribute as I would.
I struggled with the Flask-Admin doc, but it seems that's a problem with Dynamic stuff (fields or documents), and there's nothing about it in the docs.
Thanks for your help