article.py 640 B

12345678910111213141516171819202122232425262728
  1. from typing import Optional, Any
  2. from pydantic import BaseModel
  3. from fastapi import Form
  4. # Shared properties
  5. class ArticleBase(BaseModel):
  6. title: Optional[str] = None
  7. link: Optional[str] = None
  8. content: Optional[str] = None
  9. # Properties to receive on video creation
  10. class ArticleCreate(ArticleBase):
  11. title: str
  12. @classmethod
  13. def as_form(
  14. cls,
  15. title: str = Form(...),
  16. link: str = Form(None),
  17. content: str = Form(None)
  18. ) -> Any:
  19. return cls(title=title, link=link, content=content)
  20. # Properties to receive via API on update
  21. class ArticleUpdate(ArticleBase):
  22. pass