shcool/school/models/elective.py
2026-08-03 12:03:31 +08:00

42 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from odoo import fields, models, api
class Elective(models.Model):
_name = 'yuthon.school.elective'
_description = '选修课'
name = fields.Char(
string='选修课名称',
required=True,
help='Odoo 工作流开发、OWL 前端框架入门',
)
description = fields.Text(
string='课程简介',
)
teacher_id = fields.Many2one(
'yuthon.school.teacher',
string='授课教师',
)
student_ids = fields.Many2many(
'yuthon.school.student',
'yuthon_elective_student_rel',
'elective_id',
'student_id',
string='选课学生',
help='选择选修该课程的学生Many2many 关系演示)',
)
student_count = fields.Integer(
string='选课人数',
compute='_compute_student_count',
store=True,
)
active = fields.Boolean(
string='启用',
default=True,
)
@api.depends('student_ids')
def _compute_student_count(self):
for record in self:
record.student_count = len(record.student_ids)