12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #!/usr/bin/env python
- """
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2024/03/24 13:53:49
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc : item model
- """
- from sqlmodel import Field, Relationship, SQLModel
- from .user import User
- class ItemBase(SQLModel):
- title: str
- description: str | None = None
- class Item(SQLModel, table=True):
- id: int | None = Field(default=None, primary_key=True)
- title: str
- owner_id: int | None = Field(default=None, foreign_key="user.id", nullable=False)
- owner: User | None = Relationship(back_populates="items")
- # Properties to receive on item creation
- class ItemCreate(ItemBase):
- title: str
- # Properties to receive on item update
- class ItemUpdate(ItemBase):
- title: str | None = None # type: ignore
- # Properties to return via API, id is always required
- class ItemOut(ItemBase):
- id: int
- owner_id: int
- class ItemsOut(SQLModel):
- data: list[ItemOut]
- count: int
|