Automated Action 06df0285b1 Implement Blogging Platform API with FastAPI and SQLite
- Set up project structure and dependencies
- Create database models for users, posts, comments, and tags
- Set up Alembic for database migrations
- Implement user authentication (register, login)
- Create CRUD endpoints for blog posts, comments, and tags
- Add health check endpoint
- Set up proper error handling
- Update README with project details and setup instructions
2025-06-02 21:58:50 +00:00

23 lines
949 B
Python

from datetime import datetime
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, Boolean
from sqlalchemy.orm import relationship
from app.db.session import Base
from app.models.tag import post_tag
class Post(Base):
__tablename__ = "posts"
id = Column(Integer, primary_key=True, index=True)
title = Column(String(255), nullable=False)
content = Column(Text, nullable=False)
published = Column(Boolean, default=True)
author_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
author = relationship("User", back_populates="posts")
comments = relationship("Comment", back_populates="post", cascade="all, delete-orphan")
tags = relationship("Tag", secondary=post_tag, back_populates="posts")