user collection model

This commit is contained in:
Анатолий Богомолов 2024-02-24 22:34:54 +10:00
parent ac79aefa36
commit c86fd6dd8e
4 changed files with 19 additions and 4 deletions

View File

@ -2,7 +2,6 @@ from typing import List
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.task import Task
from app.models.user import User
from app.extensions import db
class Session(db.Model):
@ -10,7 +9,6 @@ class Session(db.Model):
name: Mapped[str] = mapped_column(unique=True)
authorized: Mapped[bool]
users: Mapped[List[User]] = relationship("User", cascade="all, delete-orphan", back_populates="session")
tasks: Mapped[List[Task]] = relationship("Task", cascade="all, delete-orphan", back_populates="session")

View File

@ -13,6 +13,10 @@ class Task(db.Model):
session_id = Column(Integer, ForeignKey("session.id"))
session: Mapped['Session'] = relationship("Session", back_populates="tasks")
collection_id = Column(Integer, ForeignKey("collection.id"))
collection: Mapped['UsersCollection'] = relationship('UsersCollection', back_populates='task')
datetime: Mapped[DateTime] = Column(DateTime, default=datetime.datetime.utcnow())
status: Mapped[str]
status_message: Mapped[str]

View File

@ -15,5 +15,5 @@ class User(db.Model):
phone: Mapped[str] = mapped_column(nullable=True, unique=True)
username: Mapped[str] = mapped_column(nullable=True, unique=True)
session_id = Column(Integer, ForeignKey("session.id"))
session: Mapped["Session"] = relationship("Session", back_populates="users")
collection_id = Column(Integer, ForeignKey("collection.id"))
collection: Mapped["UsersCollection"] = relationship("UsersCollection", back_populates="users")

View File

@ -0,0 +1,13 @@
from typing import List
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.extensions import db
from app.models.task import Task
from app.models.user import User
class UsersCollection(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
Mapped[List[Task]] = relationship("Task", back_populates="collection")
users: Mapped[List[User]] = relationship("User", cascade="all, delete-orphan", back_populates="collection")