From 5c8f8fa895d91de49369695271a86c5dcb87d37b 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 18:01:55 +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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/college/models/exam.py b/college/models/exam.py index 380324e..bab9d2f 100644 --- a/college/models/exam.py +++ b/college/models/exam.py @@ -31,7 +31,8 @@ class ExamQuestion(models.Model): _rec_name = 'question_text_short' sequence = fields.Integer(string='排序', default=10) - name = fields.Char(string='题目标题', help='内部管理用,不展示给学生', required=True) + name = fields.Char(string='题目标题', compute='_compute_name', store=True, + help='自动取题干文本(与题干一致),内部管理用,不展示给学生') question_text = fields.Html(string='题干', sanitize=True, required=True) question_text_short = fields.Char( string='题干摘要', compute='_compute_question_text_short', store=True) @@ -83,6 +84,13 @@ class ExamQuestion(models.Model): text = re.sub(r'\s+', ' ', text).strip() q.question_text_short = (text[:40] + '…') if len(text) > 40 else text + @api.depends('question_text') + def _compute_name(self): + import re + for q in self: + text = re.sub(r'<[^>]+>', ' ', q.question_text or '') + q.name = re.sub(r'\s+', ' ', text).strip() + @api.model def default_get(self, fields_list): """新建题目时,单选/多选题默认带 A/B/C/D 四个选项行。""" -- 2.34.1