Files
François Voron 104a6c6bf5 Inject every models variations and DB model in DB adapters (#84)
* Inject every model variations in router and DB model in DB adapters

* Update documentation and import Tortoise in db module

* Use path operation decorator dependencies for superuser routes
2020-01-04 15:36:34 +01:00

47 lines
964 B
Python

import uuid
from typing import Optional, TypeVar
import pydantic
from pydantic import BaseModel, EmailStr
class BaseUser(BaseModel):
"""Base User model."""
id: Optional[str] = None
email: Optional[EmailStr] = None
is_active: Optional[bool] = True
is_superuser: Optional[bool] = False
@pydantic.validator("id", pre=True, always=True)
def default_id(cls, v):
return v or str(uuid.uuid4())
def create_update_dict(self):
return self.dict(
exclude_unset=True, exclude={"id", "is_superuser", "is_active"}
)
def create_update_dict_superuser(self):
return self.dict(exclude_unset=True, exclude={"id"})
class BaseUserCreate(BaseUser):
email: EmailStr
password: str
class BaseUserUpdate(BaseUser):
password: Optional[str]
class BaseUserDB(BaseUser):
id: str
hashed_password: str
class Config:
orm_mode = True
UD = TypeVar("UD", bound=BaseUserDB)