12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #!/usr/bin/env python
- """
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2024/03/22 18:06:30
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc : user model
- """
- from sqlmodel import Field, Relationship, SQLModel
- class UserBase(SQLModel):
- email: str = Field(unique=True, index=True)
- is_active: bool = True
- is_superuser: bool = False
- full_name: str | None = None
- class User(UserBase, table=True):
- id: int | None = Field(default=None, primary_key=True)
- hashed_password: str
- items: list["Item"] = Relationship(back_populates="owner")
- # Properties to receive via API on creation
- class UserCreate(UserBase):
- password: str
- # TODO replace email str with EmailStr when sqlmodel supports it
- class UserCreateOpen(SQLModel):
- email: str
- password: str
- full_name: str | None = None
- # Properties to receive via API on update, all are optional
- # TODO replace email str with EmailStr when sqlmodel supports it
- class UserUpdate(UserBase):
- email: str | None = None # type: ignore
- password: str | None = None
- # TODO replace email str with EmailStr when sqlmodel supports it
- class UserUpdateMe(SQLModel):
- full_name: str | None = None
- email: str | None = None
- class UpdatePassword(SQLModel):
- current_password: str
- new_password: str
- # Properties to return via API, id is always required
- class UserOut(UserBase):
- id: int
- class UsersOut(SQLModel):
- data: list[UserOut]
- count: int
|