O2Sound_ver2_final/backend/app/domain/models/video.py

34 lines
1.6 KiB
Python

from sqlalchemy import Column, String, ForeignKey, Boolean, Integer
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from app.domain.models.base import BaseModel
class Video(BaseModel):
'''비디오 모델'''
__tablename__ = "videos"
# 외래키
music_id = Column(UUID(as_uuid=True), ForeignKey('musics.id'), nullable=False, unique=True)
order_id = Column(UUID(as_uuid=True), ForeignKey('orders.id'), nullable=False)
title = Column(String, nullable=False) # 비디오 제목
description = Column(String, nullable=False) # 비디오 설명
url = Column(String, nullable=False) # 비디오 주소
is_uploaded = Column(Boolean, nullable=False) # 비디오 업로드 여부
download_count = Column(Integer, nullable=False) # 비디오 다운로드 수
resolution = Column(String, nullable=False) # 비디오 해상도
status = Column(String, nullable=True, default="완료됨") # 비디오 상태 ( 예: 준비중, 업로드중, 업로드완료 )
thumbnail_url = Column(String, nullable=True) # 비디오 썸네일 주소
# 관계 설정
# ( videos --- 1:N --- uploads )
# ( videos --- 1:N --- photos )
# video가 없어도 photo는 있을 수 있어서 cascade 안함
uploads = relationship("Upload", back_populates="video", cascade="all, delete-orphan")
photos = relationship("Photo", back_populates="video", order_by="Photo.video_index")
# ( videos --- N:1 --- orders )
order = relationship("Order", back_populates="videos")
# ( videos --- 1:1 --- musics )
music = relationship("Music", back_populates="video", uselist=False)