from database import db_connection class Organization(db_connection.Model): __tablename__ = 'organizations' 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) users = db_connection.Column(db_connection.JSON, nullable=False, default=dict) owner_id = db_connection.Column(db_connection.Integer, db_connection.ForeignKey('users.id')) owner = db_connection.relationship('User', backref=db_connection.backref('owned_organization', uselist=False)) files = db_connection.relationship('File', back_populates='org') def to_dict(self): return { "id": self.id, "name": self.name, "owner": self.owner.to_dict(), "users": [{"id": user_id, "user_data": { "username": user_data["username"], "full_name": user_data["full_name"], "email": user_data["email"], "status": user_data["status"] }} for user_id, user_data in self.users.items()], "files": [{"id": file.id, "name": file.name, "file_handle": file.file_handle} for file in self.files] }