-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
66 lines (44 loc) · 1.45 KB
/
Copy pathmodels.py
File metadata and controls
66 lines (44 loc) · 1.45 KB
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
from main import db
class ProjectModel(db.Model):
__tablename__ = 'projects'
id = db.Column(db.Integer,primary_key=True)
title = db.Column(db.String(120),nullable=False,unique=True)
description = db.Column(db.String(),nullable=True)
startDate = db.Column(db.String(50),nullable=False)
endDate = db.Column(db.String(50),nullable=False)
cost = db.Column(db.Integer,nullable=False)
status = db.Column(db.String(30))
# CREATE
def create_record(self):
db.session.add(self)
db.session.commit()
# READ
@classmethod
def fetch_all(cls):
records = ProjectModel.query.all()
return records
#UPDATE
@classmethod
def update_by_id(cls,id,newTitle,newDescription,newStartDate,newEndDate,newCost,newStatus):
record = ProjectModel.query.filter_by(id=id).first()
if record:
record.title = newTitle
record.description = newDescription
record.startDate = newStartDate
record.endDate = newEndDate
record.cost = newCost
record.status = newStatus
db.session.commit()
return True
else:
return False
#DELETE
@classmethod
def delete_by_id(cls,id):
record = ProjectModel.query.filter_by(id=id)
if record.first():
record.delete()
db.session.commit()
return True
else:
return False