item.py 974 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. """
  3. @Contact : liuyuqi.gov@msn.cn
  4. @Time : 2024/03/24 13:53:49
  5. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  6. @Desc : item model
  7. """
  8. from sqlmodel import Field, Relationship, SQLModel
  9. from .user import User
  10. class ItemBase(SQLModel):
  11. title: str
  12. description: str | None = None
  13. class Item(SQLModel, table=True):
  14. id: int | None = Field(default=None, primary_key=True)
  15. title: str
  16. owner_id: int | None = Field(default=None, foreign_key="user.id", nullable=False)
  17. owner: User | None = Relationship(back_populates="items")
  18. # Properties to receive on item creation
  19. class ItemCreate(ItemBase):
  20. title: str
  21. # Properties to receive on item update
  22. class ItemUpdate(ItemBase):
  23. title: str | None = None # type: ignore
  24. # Properties to return via API, id is always required
  25. class ItemOut(ItemBase):
  26. id: int
  27. owner_id: int
  28. class ItemsOut(SQLModel):
  29. data: list[ItemOut]
  30. count: int