FastAPI-Project / app /models /posts.py
abdullah090809's picture
initial commit
55fd541
Raw
History Blame Contribute Delete
643 Bytes
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean, TIMESTAMP, text
from sqlalchemy.orm import relationship
from app.database import Base
class Post(Base):
__tablename__ = "posts"
id = Column(Integer, primary_key=True, nullable=False)
title = Column(String, nullable=False)
content = Column(String, nullable=False)
published = Column(Boolean, server_default="TRUE", nullable=False)
created_at = Column(TIMESTAMP(timezone=True), nullable=False, server_default=text("now()"))
owner_id = Column(Integer, ForeignKey("users.id",ondelete="CASCADE"),nullable=False)
owner = relationship("User")