2024-11-13 02:49:43 +00:00
|
|
|
from database import db_connection
|
2024-11-12 01:33:31 +00:00
|
|
|
|
2024-11-13 02:49:43 +00:00
|
|
|
class Organization(db_connection.Model):
|
2024-11-12 01:33:31 +00:00
|
|
|
__tablename__ = 'organizations'
|
|
|
|
|
2024-11-13 02:49:43 +00:00
|
|
|
id = db_connection.Column(db_connection.Integer, primary_key=True, index=True)
|
|
|
|
name = db_connection.Column(db_connection.String, unique=True, index=True, nullable=False)
|
|
|
|
owner_id = db_connection.Column(db_connection.Integer, db_connection.ForeignKey('users.id'), nullable=False)
|
|
|
|
owner = db_connection.relationship('User', back_populates='orgs')
|
|
|
|
files = db_connection.relationship('File', back_populates='org')
|
|
|
|
|
|
|
|
def to_dict(self):
|
|
|
|
return {
|
|
|
|
"id": self.id,
|
|
|
|
"name": self.name,
|
|
|
|
"owner": self.owner.to_dict(),
|
|
|
|
"files": [{"id": file.id, "name": file.name, "file_handle": file.file_handle} for file in self.files]
|
|
|
|
}
|