PaperParser/app/models/collection.py

17 lines
614 B
Python

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)
name: Mapped[str] = mapped_column(unique=True, nullable=False)
tasks: Mapped[List['Task']] = relationship("Task", back_populates="collection")
users: Mapped[List['User']] = relationship("User", cascade="all, delete-orphan", back_populates="collection")
def exists(name: str):
collections = Collection.query.filter_by(name=name).all()
return len(collections) > 0