-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
23 lines (18 loc) · 903 Bytes
/
models.py
File metadata and controls
23 lines (18 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Organization(db.Model):
__tablename__ = 'organizations'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
address = db.Column(db.String(200), nullable=True)
users = db.relationship('User', backref='organization', lazy=True)
def to_dict(self):
return {"id": self.id, "name": self.name, "address": self.address}
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
email = db.Column(db.String(100), nullable=False, unique=True)
organization_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
def to_dict(self):
return {"id": self.id, "name": self.name, "email": self.email, "organization_id": self.organization_id}