123456789101112131415161718192021222324252627282930313233343536373839404142 |
- from contextlib import closing
- from typing import Iterator
- from pycs import db
- from pycs.database.base import NamedBaseModel
- class Collection(NamedBaseModel):
- # table columns
- project_id = db.Column(
- db.Integer, db.ForeignKey("project.id", ondelete="CASCADE"), nullable=False)
- reference = db.Column(
- db.String, nullable=False)
- description = db.Column(
- db.String)
- position = db.Column(
- db.Integer, nullable=False)
- autoselect = db.Column(
- db.Boolean, nullable=False)
- # contraints
- __table_args__ = (
- db.UniqueConstraint('project_id', 'reference'),
- )
- # relationships to other models
- files = db.relationship("File", backref="collection", lazy=True)
- def count_files(self) -> int:
- return self.files.count()
- # def files_it(self, offset: int = 0, limit: int = -1) -> Iterator[File]:
- # # self.files.filter
- # files = File.query.filter_by(project_id=self.project_id, collection_id=self.id)
- # raise NotImplementedError
|