-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
60 lines (40 loc) · 1.53 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.dialects.postgresql import JSONB
def create_app(config):
app = Flask(__name__)
app.config.from_object(config)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
return app
app = create_app(os.environ['APP_ENV'])
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.String(24), primary_key=True)
groups = db.Column(JSONB)
def __init__(self, id, groups=None):
self.id = id
self.groups = groups if groups is not None else list()
def __repr__(self):
return '<User: {} groups: {}>'.format(self.id, self.groups)
class Group(db.Model):
__tablename__ = 'groups'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(), index=True, unique=True, nullable=False)
description = db.Column(db.String(), nullable=True)
def __init__(self, name, description=""):
self.name = name
self.description = description
def __repr__(self):
return '<Group {} id: {}>'.format(self.name, self.id)
class Resource(db.Model):
__tablename__ = 'resources'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(), index=True, unique=True, nullable=False)
groups = db.Column(JSONB)
def __init__(self, name, groups=None):
self.name = name
self.groups = groups if groups is not None else list()
def __repr__(self):
return '<Resource: {} id: {}>'.format(self.name, self.id)