6
0

Collection.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from contextlib import closing
  2. from typing import Iterator
  3. from pycs import db
  4. from pycs.database.base import NamedBaseModel
  5. class Collection(NamedBaseModel):
  6. # table columns
  7. project_id = db.Column(
  8. db.Integer, db.ForeignKey("project.id", ondelete="CASCADE"), nullable=False)
  9. reference = db.Column(
  10. db.String, nullable=False)
  11. description = db.Column(
  12. db.String)
  13. position = db.Column(
  14. db.Integer, nullable=False)
  15. autoselect = db.Column(
  16. db.Boolean, nullable=False)
  17. # contraints
  18. __table_args__ = (
  19. db.UniqueConstraint('project_id', 'reference'),
  20. )
  21. # relationships to other models
  22. files = db.relationship("File", backref="collection", lazy=True)
  23. def count_files(self) -> int:
  24. return self.files.count()
  25. # def files_it(self, offset: int = 0, limit: int = -1) -> Iterator[File]:
  26. # # self.files.filter
  27. # files = File.query.filter_by(project_id=self.project_id, collection_id=self.id)
  28. # raise NotImplementedError