34 lines
1009 B
Python

Here's the `comments.py` file for the `app/api/v1/schemas/` directory in the `blog_app_igblf` FastAPI backend project:
from datetime import datetime
from typing import Optional
from pydantic import BaseModel
class CommentBase(BaseModel):
content: str
class CommentCreate(CommentBase):
pass
class CommentUpdate(CommentBase):
pass
class CommentInDBBase(CommentBase):
id: int
post_id: int
created_at: datetime
updated_at: Optional[datetime] = None
class Config:
orm_mode = True
class Comment(CommentInDBBase):
pass
class CommentInDB(CommentInDBBase):
pass
This file defines the following Pydantic models for comments:
4. `CommentInDBBase`: A base model that includes fields for the comment ID (`id`), the associated post ID (`post_id`), the creation timestamp (`created_at`), and an optional update timestamp (`updated_at`). This model inherits from `CommentBase` and includes the `orm_mode` configuration to allow reading data from an SQLAlchemy model.