Files
freetable/backend/app/models/attachment.py
T

32 lines
1.2 KiB
Python
Raw Normal View History

2026-06-09 23:31:05 +00:00
from datetime import datetime
from typing import Optional
from sqlalchemy import String, DateTime, ForeignKey, Integer, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
2026-06-09 23:31:05 +00:00
from app.database import Base
2026-06-09 23:31:05 +00:00
class Attachment(Base):
__tablename__ = "attachments"
id: Mapped[int] = mapped_column(primary_key=True)
record_id: Mapped[int] = mapped_column(
ForeignKey("records.id", ondelete="CASCADE"), nullable=False, index=True
)
column_id: Mapped[int] = mapped_column(
ForeignKey("columns.id", ondelete="CASCADE"), nullable=True
)
filename: Mapped[str] = mapped_column(String(255), nullable=False)
file_path: Mapped[str] = mapped_column(String(500), nullable=False)
file_size: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
mime_type: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
uploaded_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
# Relationships
record = relationship("Record", back_populates="attachments")
column = relationship("Column", back_populates="attachments")
def __repr__(self):
return f"<Attachment(id={self.id}, filename={self.filename})>"