6
0

Collection.py 1.1 KB

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