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

32 lines
1.6 KiB
Python

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=True)
document_handle = db_connection.Column(db_connection.String, unique=True, nullable=False)
name = db_connection.Column(db_connection.String, nullable=False)
created_at = db_connection.Column(db_connection.Integer, nullable=False)
key = db_connection.Column(db_connection.String, nullable=False)
alg = db_connection.Column(db_connection.String, nullable=False)
nonce = 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', backref=db_connection.backref('org_files', uselist=False))
creator = db_connection.relationship('User', backref=db_connection.backref('created_files', uselist=False))
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,
"key": self.key,
"alg": self.alg,
"nonce": self.nonce,
"org": {"id": self.org.id, "name": self.org.name},
"creator": {"id": self.creator.id, "username": self.creator.username}
}