Files
dt_audio/courses/Course.py
2024-05-26 09:36:58 +08:00

28 lines
888 B
Python

from courses.Attachment import Attachment
class Course:
def __init__(self, course_id, title, attachments=None):
self.id = course_id
self.title = title
self.attachments = attachments if attachments else []
def add_attachment(self, attachment):
self.attachments.append(attachment)
def __repr__(self):
return f"Course(id={self.id}, title={self.title}, attachments={self.attachments})"
# 使用示例
# 创建附件实例
attachment1 = Attachment(attachment_id=1, course_id=101, name='Lesson 1', url='http://example.com/lesson1.mp3')
attachment2 = Attachment(attachment_id=2, course_id=101, name='Lesson 2', url='http://example.com/lesson2.mp3')
# 创建课程实例,并添加附件
course = Course(course_id=101, title='Introduction to Python')
course.add_attachment(attachment1)
course.add_attachment(attachment2)
print(course)