PaperParser/app/models/collection.py

17 lines
614 B
Python
Raw Permalink Normal View History

2024-02-25 00:11:48 +10:00
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)
2024-03-07 02:22:24 +10:00
name: Mapped[str] = mapped_column(unique=True, nullable=False)
2024-02-25 00:11:48 +10:00
tasks: Mapped[List['Task']] = relationship("Task", back_populates="collection")
2024-03-08 16:39:04 +10:00
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