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

75 lines
2.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 VideoCategory(models.Model):
_name = 'yuthon.school.category'
_description = '学习目录'
_order = 'complete_name'
_parent_store = True
name = fields.Char(
string='目录名称',
required=True,
help='Odoo 基础入门、模型开发、视图开发等',
)
parent_id = fields.Many2one(
'yuthon.school.category',
string='上级目录',
index=True,
ondelete='restrict',
help='选择上级目录以建立层级结构',
)
parent_path = fields.Char(
index=True,
unaccent=False,
)
child_ids = fields.One2many(
'yuthon.school.category',
'parent_id',
string='下级目录',
)
complete_name = fields.Char(
string='完整路径',
compute='_compute_complete_name',
store=True,
recursive=True,
help='显示完整路径Odoo 开发 > 模型开发 > 关系字段',
)
level = fields.Selection(
[('beginner', '入门'), ('intermediate', '进阶'), ('advanced', '高级')],
string='难度等级',
default='beginner',
help='该目录对应的学习难度',
)
description = fields.Text(
string='目录说明',
help='该学习目录的详细说明',
)
video_ids = fields.One2many(
'yuthon.school.video',
'category_id',
string='教学视频',
)
video_count = fields.Integer(
string='视频数量',
compute='_compute_video_count',
store=True,
)
active = fields.Boolean(
string='启用',
default=True,
)
@api.depends('name', 'parent_id.complete_name')
def _compute_complete_name(self):
for record in self:
if record.parent_id:
record.complete_name = f'{record.parent_id.complete_name} > {record.name}'
else:
record.complete_name = record.name
@api.depends('video_ids')
def _compute_video_count(self):
for record in self:
record.video_count = len(record.video_ids)