diff --git a/app/models/session.py b/app/models/session.py index 9d4707d..2f44cb1 100644 --- a/app/models/session.py +++ b/app/models/session.py @@ -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") diff --git a/app/models/task.py b/app/models/task.py index 71756d0..a6d15a4 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -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] diff --git a/app/models/user.py b/app/models/user.py index 510b00b..9266261 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -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") \ No newline at end of file + collection_id = Column(Integer, ForeignKey("collection.id")) + collection: Mapped["UsersCollection"] = relationship("UsersCollection", back_populates="users") \ No newline at end of file diff --git a/app/models/user_collection.py b/app/models/user_collection.py new file mode 100644 index 0000000..4d6fc34 --- /dev/null +++ b/app/models/user_collection.py @@ -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") \ No newline at end of file