feat: add models part 2

This commit is contained in:
firedotguy
2026-01-31 18:28:23 +03:00
parent a388426d8d
commit 2a9f7da9a9
9 changed files with 183 additions and 48 deletions

View File

@@ -1,17 +1,26 @@
from uuid import UUID
from datetime import datetime
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, field_validator
from itd.models.user import UserPost
from itd.models.file import Attach
class TextObject(BaseModel):
id: UUID
content: str
author: UserPost
attachments: list[UUID]
attachments: list[Attach] = []
created_at: datetime = Field(alias='createdAt')
model_config = {'populate_by_name': True}
model_config = {'populate_by_name': True}
@field_validator('created_at', mode='plain')
@classmethod
def validate_created_at(cls, v: str):
try:
return datetime.strptime(v + '00', '%Y-%m-%d %H:%M:%S.%f%z')
except ValueError:
return datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%fZ')