25 lines
1.0 KiB
Python

from typing import List
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.domain.models.base import RootTable
class Lesson(RootTable):
__tablename__ = 'lessons'
title: Mapped[str] = mapped_column(String(250), nullable=False)
description: Mapped[str] = mapped_column(nullable=True)
text: Mapped[str] = mapped_column(nullable=True)
number: Mapped[int] = mapped_column(nullable=False)
course_id: Mapped[int] = mapped_column(ForeignKey('courses.id'), nullable=False)
creator_id: Mapped[int] = mapped_column(ForeignKey('users.id'), nullable=False)
course: Mapped['Course'] = relationship('Course', back_populates='lessons')
creator: Mapped['User'] = relationship('User', back_populates='created_lessons', lazy='joined')
files: Mapped[List['LessonFile']] = relationship('LessonFile', back_populates='lesson')
user_check_lessons: Mapped[List['UserCheckLessons']] = relationship('UserCheckLessons', back_populates='lesson', cascade="all, delete-orphan",)