From 285aeed4750babf51b5801dd6a9c66702b9500a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Thu, 17 Sep 2026 17:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=95=99=E8=82=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- college/models/exam.py | 16 ++++++++++++++++ college/views/exam_views.xml | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) 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'"/> -- 2.34.1