26 lines
954 B
Python
26 lines
954 B
Python
"""
|
|
Post model for the PostgreSQL database
|
|
"""
|
|
from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey, func, UUID
|
|
from sqlalchemy.orm import relationship
|
|
import uuid
|
|
from app import Base
|
|
|
|
class Post(Base):
|
|
"""Post model representing a blog post or article in the system"""
|
|
__tablename__ = 'posts'
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
user_id = Column(UUID(as_uuid=True), ForeignKey('users.id', ondelete='CASCADE'), nullable=False, index=True)
|
|
title = Column(String(200), nullable=False)
|
|
content = Column(Text)
|
|
is_published = Column(Boolean, default=False)
|
|
created_at = Column(DateTime, default=func.now())
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="posts")
|
|
|
|
def __repr__(self):
|
|
return f"<Post(title='{self.title}', user_id='{self.user_id}')>"
|