From c86fd6dd8ea0cfba586f4e50f9900b7d661bd27a Mon Sep 17 00:00:00 2001 From: winet Date: Sat, 24 Feb 2024 22:34:54 +1000 Subject: [PATCH] user collection model --- app/models/session.py | 2 -- app/models/task.py | 4 ++++ app/models/user.py | 4 ++-- app/models/user_collection.py | 13 +++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 app/models/user_collection.py 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