45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
from datetime import datetime
|
|
from uuid import UUID, uuid1
|
|
|
|
from sqlalchemy import TIMESTAMP, ForeignKey, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from src.models.database_models.model import Model
|
|
|
|
|
|
class Stored(Model):
|
|
__tablename__="reports"
|
|
|
|
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
|
doc_id:Mapped[UUID]=mapped_column(default=uuid1, unique=True)
|
|
filename:Mapped[str]=mapped_column(String(255), index=True)
|
|
created_at:Mapped[datetime]=mapped_column(TIMESTAMP(timezone=True), server_default=func.now())
|
|
uploaded_at:Mapped[datetime]=mapped_column(TIMESTAMP(timezone=True),onupdate=func.now(), nullable=True)
|
|
doc_date:Mapped[datetime]=mapped_column(TIMESTAMP(timezone=True))
|
|
status:Mapped[str]=mapped_column(String(64))
|
|
user_id:Mapped[UUID]=mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
|
market_id:Mapped[int]=mapped_column(ForeignKey("markets.id", ondelete="CASCADE"),index=True)
|
|
|
|
|
|
user:Mapped["User"]=relationship(back_populates="report")
|
|
market:Mapped["Markets"]=relationship(back_populates="report")
|
|
def __repr__(self) -> str:
|
|
return f'ID: {self.id}, Filename: {self.filename}, Status: {self.status}'
|
|
|
|
class Markets(Model):
|
|
__tablename__="markets"
|
|
|
|
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
|
name:Mapped[str]=mapped_column(String(64), unique=True)
|
|
|
|
report:Mapped[list["Stored"]]=relationship(back_populates="market")
|
|
def __repr__(self) -> str:
|
|
return f'ID: {self.id}, Name: {self.name}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|