64 lines
1.0 KiB
Python
64 lines
1.0 KiB
Python
from datetime import datetime
|
|
from typing import Optional, List, Generic, T
|
|
|
|
from ninja import Schema
|
|
|
|
|
|
# --- 假设的关联模型 Schema ---
|
|
class AuthorSchema(Schema):
|
|
id: int
|
|
username: str
|
|
|
|
|
|
class SectionSchema(Schema):
|
|
id: int
|
|
title: str # 假设 MainMenu 有 name 字段
|
|
|
|
|
|
class ArticleAttachmentOut(Schema):
|
|
id: int
|
|
file: str
|
|
|
|
|
|
class ArticleListOut(Schema):
|
|
id: int
|
|
title: str
|
|
|
|
section: SectionSchema
|
|
|
|
author: AuthorSchema
|
|
|
|
cover: Optional[str] = None
|
|
is_contribution: bool
|
|
is_published: bool
|
|
|
|
|
|
class ArticleDetailOut(Schema):
|
|
id: int
|
|
title: str
|
|
|
|
section: SectionSchema
|
|
|
|
author: AuthorSchema
|
|
|
|
content: str
|
|
cover: Optional[str] = None
|
|
|
|
is_contribution: bool
|
|
is_published: bool
|
|
|
|
attachments: List[ArticleAttachmentOut] = []
|
|
|
|
|
|
class ArticleCreate(Schema):
|
|
title: str
|
|
section_id: Optional[int] = None
|
|
author_id: Optional[int] = None
|
|
content: str
|
|
is_contribution: bool = False
|
|
is_published: bool = True
|
|
|
|
|
|
class ArticleUpdate(ArticleCreate):
|
|
pass
|