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

18 lines
809 B
Python

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)
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]
}