fixed
This commit is contained in:
parent
c86fd6dd8e
commit
e9cf18d0e6
|
@ -41,7 +41,7 @@ async def parse_users(session_id: int):
|
||||||
|
|
||||||
@users.route("/<int:session_id>", methods=["GET"])
|
@users.route("/<int:session_id>", methods=["GET"])
|
||||||
def get_users(session_id: int):
|
def get_users(session_id: int):
|
||||||
users = Session.query.get_or_404(session_id).users
|
users = [] #Session.query.get_or_404(session_id)
|
||||||
|
|
||||||
return render_template("user_cards.j2", users=users)
|
return render_template("user_cards.j2", users=users)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
|
||||||
|
from app.extensions import db
|
||||||
|
|
||||||
|
class Collection(db.Model):
|
||||||
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||||||
|
|
||||||
|
tasks: Mapped[List['Task']] = relationship("Task", back_populates="collection")
|
||||||
|
users: Mapped[List['User']] = relationship("User", cascade="all, delete-orphan", back_populates="collection")
|
|
@ -4,6 +4,7 @@ from sqlalchemy import Integer, DateTime
|
||||||
from sqlalchemy.schema import Column, ForeignKey
|
from sqlalchemy.schema import Column, ForeignKey
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
from app.models.collection import Collection
|
||||||
|
|
||||||
class Task(db.Model):
|
class Task(db.Model):
|
||||||
id: Mapped[int] = mapped_column(primary_key=True)
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||||||
|
@ -15,7 +16,7 @@ class Task(db.Model):
|
||||||
session: Mapped['Session'] = relationship("Session", back_populates="tasks")
|
session: Mapped['Session'] = relationship("Session", back_populates="tasks")
|
||||||
|
|
||||||
collection_id = Column(Integer, ForeignKey("collection.id"))
|
collection_id = Column(Integer, ForeignKey("collection.id"))
|
||||||
collection: Mapped['UsersCollection'] = relationship('UsersCollection', back_populates='task')
|
collection: Mapped['Collection'] = relationship('Collection', back_populates='tasks')
|
||||||
|
|
||||||
datetime: Mapped[DateTime] = Column(DateTime, default=datetime.datetime.utcnow())
|
datetime: Mapped[DateTime] = Column(DateTime, default=datetime.datetime.utcnow())
|
||||||
status: Mapped[str]
|
status: Mapped[str]
|
||||||
|
|
|
@ -16,4 +16,4 @@ class User(db.Model):
|
||||||
username: Mapped[str] = mapped_column(nullable=True, unique=True)
|
username: Mapped[str] = mapped_column(nullable=True, unique=True)
|
||||||
|
|
||||||
collection_id = Column(Integer, ForeignKey("collection.id"))
|
collection_id = Column(Integer, ForeignKey("collection.id"))
|
||||||
collection: Mapped["UsersCollection"] = relationship("UsersCollection", back_populates="users")
|
collection: Mapped["Collection"] = relationship("Collection", back_populates="users")
|
|
@ -1,13 +0,0 @@
|
||||||
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")
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
"""user collections
|
||||||
|
|
||||||
|
Revision ID: 21750f5bbab1
|
||||||
|
Revises: cdd471f48b0d
|
||||||
|
Create Date: 2024-02-24 22:47:05.197801
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '21750f5bbab1'
|
||||||
|
down_revision = 'cdd471f48b0d'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('collection',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('task', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('collection_id', sa.Integer(), nullable=True))
|
||||||
|
batch_op.create_foreign_key(None, 'collection', ['collection_id'], ['id'])
|
||||||
|
|
||||||
|
with op.batch_alter_table('user', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('collection_id', sa.Integer(), nullable=True))
|
||||||
|
batch_op.drop_constraint('user_session_id_fkey', type_='foreignkey')
|
||||||
|
batch_op.create_foreign_key(None, 'collection', ['collection_id'], ['id'])
|
||||||
|
batch_op.drop_column('session_id')
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('user', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('session_id', sa.INTEGER(), autoincrement=False, nullable=True))
|
||||||
|
batch_op.drop_constraint(None, type_='foreignkey')
|
||||||
|
batch_op.create_foreign_key('user_session_id_fkey', 'session', ['session_id'], ['id'])
|
||||||
|
batch_op.drop_column('collection_id')
|
||||||
|
|
||||||
|
with op.batch_alter_table('task', schema=None) as batch_op:
|
||||||
|
batch_op.drop_constraint(None, type_='foreignkey')
|
||||||
|
batch_op.drop_column('collection_id')
|
||||||
|
|
||||||
|
op.drop_table('collection')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in New Issue