25 lines
1.0 KiB
Python

Here's a `comments.py` file for the `app/api/v1/models/` directory of the `blog_app_h23t0` FastAPI backend:
from typing import Optional
from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship
from app.api.db.database import Base
class Comments(Base):
__tablename__ = 'comments'
id = Column(Integer, primary_key=True, index=True)
post_id = Column(Integer, ForeignKey('posts.id'), nullable=False)
author_id = Column(Integer, ForeignKey('users.id'), nullable=False)
content = Column(Text, nullable=False)
created_at = Column(Integer, nullable=False)
updated_at = Column(Integer, nullable=True)
post = relationship('Posts', back_populates='comments')
author = relationship('Users', back_populates='comments')
def __repr__(self):
return f"Comments(id={self.id}, post_id={self.post_id}, author_id={self.author_id}, content='{self.content[:20]}...', created_at={self.created_at}, updated_at={self.updated_at})"
The class includes the following columns: