first
This commit is contained in:
31
sop-back/app/models/models.py
Normal file
31
sop-back/app/models/models.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, func
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.db.database import Base
|
||||
|
||||
|
||||
class Collection(Base):
|
||||
__tablename__ = "collections"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(120), nullable=False, unique=True)
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
|
||||
characters = relationship(
|
||||
"Character",
|
||||
back_populates="collection",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
|
||||
class Character(Base):
|
||||
__tablename__ = "characters"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
filename = Column(String(255), nullable=False)
|
||||
s3_url = Column(String(1024), nullable=False)
|
||||
collection_id = Column(
|
||||
Integer, ForeignKey("collections.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
|
||||
collection = relationship("Collection", back_populates="characters")
|
||||
Reference in New Issue
Block a user