forked from mts-ai/FastAPI-JSONAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.py
38 lines (30 loc) · 1.42 KB
/
user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""User model."""
from __future__ import annotations
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import relationship
from examples.api_for_sqlalchemy.extensions.sqlalchemy import Base
from examples.api_for_sqlalchemy.models.enums import UserStatusEnum
from examples.api_for_sqlalchemy.utils.sqlalchemy.base_model_mixin import BaseModelMixin
from examples.api_for_sqlalchemy.utils.sqlalchemy.fields.enum import EnumColumn
class User(Base, BaseModelMixin):
__tablename__ = "users"
id = Column(Integer, primary_key=True, autoincrement=True)
first_name: str = Column(String, nullable=True)
last_name: str = Column(String, nullable=True)
age: int = Column(Integer, nullable=True)
status = Column(EnumColumn(UserStatusEnum), nullable=False, default=UserStatusEnum.active)
email: str | None = Column(String, nullable=True)
posts = relationship("Post", back_populates="user", uselist=True)
bio = relationship("UserBio", back_populates="user", uselist=False)
comments = relationship("PostComment", back_populates="author", uselist=True)
computers = relationship("Computer", back_populates="user", uselist=True)
def __repr__(self):
return (
f"{self.__class__.__name__}("
f"id={self.id},"
f" first_name={self.first_name!r},"
f" last_name={self.last_name!r}"
")"
)
class Enum:
Status = UserStatusEnum