chat_back/chat_test/app/users/models.py

46 lines
1.7 KiB
Python

from datetime import date, datetime
from typing import Optional
from sqlalchemy import func, ForeignKey, DateTime
from sqlalchemy.orm import mapped_column, Mapped, relationship
from app.database import Base
# from app.users.chat.models import Chats
class Users(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str]
username: Mapped[str]
hashed_password: Mapped[str]
role: Mapped[int]
black_phoenix: Mapped[bool]
avatar_image: Mapped[Optional[str]] = mapped_column(server_default='static/images/ты уже пешка BP.png')
date_of_birth: Mapped[date]
date_of_registration: Mapped[date] = mapped_column(server_default=func.now())
message = relationship("Messages", back_populates="user")
usersxchats = relationship("UsersXChats", back_populates="user")
chat = relationship("Chats", primaryjoin='Chats.chat_for == Users.id', back_populates="user_to_exclude")
creator = relationship("Chats", primaryjoin='Chats.created_by == Users.id', back_populates="user_who_create")
verificationcode = relationship("UsersVerificationCodes", back_populates="user")
def __str__(self):
return f"Юзер {self.username}"
class UsersVerificationCodes(Base):
__tablename__ = "usersverificationcodes"
id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
code: Mapped[str]
description: Mapped[str]
date_of_creation: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
user = relationship("Users", back_populates="verificationcode")
def __str__(self):
return f"Код {self.code} для юзера {self.user_id}. {self.description}"