diff --git a/college/models/exam.py b/college/models/exam.py index 8c6241e..380324e 100644 --- a/college/models/exam.py +++ b/college/models/exam.py @@ -59,6 +59,12 @@ class ExamQuestion(models.Model): correct_answer = fields.Char( string='正确答案', help='判断题填 True/False;填空题填标准答案(多个空用 | 分隔)。选择题由「选项」的「正确答案」标记决定。') + # 判断题专用:把 True/False 映射成 对/错 展示与选择,存储仍是 True/False + correct_answer_tf = fields.Selection( + [('True', '对'), ('False', '错')], + string='正确答案', + compute='_compute_correct_answer_tf', inverse='_inverse_correct_answer_tf', + help='判断题的正确答案:对 / 错。') reference_answer = fields.Html( string='参考答案', sanitize=True, help='简答题的参考答案,供老师评阅与学生查看解析时参考。') @@ -99,6 +105,16 @@ class ExamQuestion(models.Model): if self.question_type in ('single_choice', 'multiple_choice') and not self.option_ids: self.option_ids = self._default_option_lines() + @api.depends('correct_answer') + def _compute_correct_answer_tf(self): + for q in self: + q.correct_answer_tf = q.correct_answer if q.correct_answer in ('True', 'False') else 'True' + + def _inverse_correct_answer_tf(self): + for q in self: + if q.correct_answer_tf: + q.correct_answer = q.correct_answer_tf + def _get_correct_options(self): """返回本题的正确选项记录(仅选择题有效)。""" self.ensure_one() diff --git a/college/views/exam_views.xml b/college/views/exam_views.xml index 0e0c86e..77ffce0 100644 --- a/college/views/exam_views.xml +++ b/college/views/exam_views.xml @@ -61,9 +61,12 @@ + + invisible="question_type != 'fill_blank'" + required="question_type == 'fill_blank'"/>