-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
62 lines (52 loc) · 2.45 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
61
62
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Project(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(255), nullable=False)
pid = db.Column(db.String(255), nullable=False)
group = db.Column(db.String(255), nullable=False)
description = db.Column(db.Text, nullable=False)
owner_id = db.Column(db.String(255), nullable=False)
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
def as_dict(self):
return {
'id': self.id,
'title': self.title,
'pid': self.pid,
'group': self.group,
'description': self.description,
'owner_id': self.owner_id,
'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S'),
'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S')
}
class Pathogen(db.Model):
id = db.Column(db.Integer, primary_key=True)
common_name = db.Column(db.String(255), nullable=False)
scientific_name = db.Column(db.String(255), nullable=False)
schema = db.Column(db.Text, nullable=True)
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
def as_dict(self):
return {
'id': self.id,
'common_name': self.common_name,
'scientific_name': self.scientific_name,
'schema': self.schema,
'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S'),
'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S')
}
class Study(db.Model):
id = db.Column(db.Integer, primary_key=True)
project_id = db.Column(db.Integer, db.ForeignKey('project.id'), nullable=False)
group = db.Column(db.String(255), nullable=False)
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
def as_dict(self):
return {
'id': self.id,
'project_id': self.project_id,
'group': self.group,
'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S'),
'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S')
}