sio-2425/delivery1/server/models/file.py

28 lines
1.4 KiB
Python
Raw Normal View History

from database import db_connection
class File(db_connection.Model):
__tablename__ = 'files'
id = db_connection.Column(db_connection.Integer, primary_key=True, index=True)
file_handle = db_connection.Column(db_connection.String, unique=True, nullable=False)
document_handle = db_connection.Column(db_connection.String, unique=True, nullable=True)
name = db_connection.Column(db_connection.String, nullable=False)
created_at = db_connection.Column(db_connection.Integer, nullable=False)
# alg: db_connection.Column(db_connection.String, nullable=False)
# key: db_connection.Column(db_connection.String, nullable=False)
org_id = db_connection.Column(db_connection.Integer, db_connection.ForeignKey('organizations.id'), nullable=False)
creator_id = db_connection.Column(db_connection.Integer, db_connection.ForeignKey('users.id'), nullable=False)
org = db_connection.relationship('Organization', back_populates='files')
creator = db_connection.relationship('User', back_populates='files')
def to_dict(self):
return {
"id": self.id,
"file_handle": self.file_handle,
"document_handle": self.document_handle,
"name": self.name,
"created_at": self.created_at,
"org": {"id": self.org.id, "name": self.org.name},
"creator": {"id": self.creator.id, "username": self.creator.username}
}