service_man/api/models/user_model.py

30 lines
700 B
Python

from sqlalchemy import Boolean, Column, String
from sqlalchemy.orm import Mapped
from api.schemas import UserReadDTO
from . import Base
class UserModel(Base):
__tablename__ = "users"
name: Mapped[str]
email = Column(String, unique=True)
hashed_password = Column(String)
is_active = Column(Boolean, default=True)
def __repr__(self):
return (
f"<User(id={self.id}, "
f'email="{self.email}", '
f'hashed_password="{self.hashed_password}", '
f"is_active={self.is_active})>"
)
def to_read_model(self) -> UserReadDTO:
return UserReadDTO(
id=self.id,
name=self.name,
)