def attachment_count(cls): from indico.modules.attachments.models.attachments import Attachment from indico.modules.attachments.models.folders import AttachmentFolder query = (db.select([db.func.count(Attachment.id)]) .select_from(db.join(Attachment, AttachmentFolder, Attachment.folder_id == AttachmentFolder.id)) .where(db.and_( ~AttachmentFolder.is_deleted, ~Attachment.is_deleted, (getattr(AttachmentFolder, cls.ATTACHMENT_FOLDER_ID_COLUMN) == cls.id) )) .correlate_except(AttachmentFolder, Attachment)) return db.column_property(query, deferred=True)
def _make_attachment_count_column_property(cls): from indico.modules.attachments.models.attachments import Attachment from indico.modules.attachments.models.folders import AttachmentFolder assert cls.attachment_count is None query = (db.select([db.func.count(Attachment.id)]) .select_from(db.join(Attachment, AttachmentFolder, Attachment.folder_id == AttachmentFolder.id)) .where(db.and_( ~AttachmentFolder.is_deleted, ~Attachment.is_deleted, (getattr(AttachmentFolder, cls.ATTACHMENT_FOLDER_ID_COLUMN) == cls.id) )) .correlate_except(AttachmentFolder, Attachment)) cls.attachment_count = db.column_property(query, deferred=True)