forked from AdaGold/task-list-api
-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathtask.py
28 lines (24 loc) · 903 Bytes
/
task.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
from app import db
class Task(db.Model):
task_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String)
description = db.Column(db.String)
completed_at = db.Column(db.DateTime, nullable=True)
is_completed = db.Column(db.Boolean, default=False)
goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'), nullable=True)
goal = db.relationship("Goal", back_populates="tasks")
def to_dict(self):
return {
"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": self.is_completed
}
def to_dict_in_goal(self):
return {
"id": self.task_id,
"goal_id": self.goal_id,
"title": self.title,
"description": self.description,
"is_complete": self.is_completed
}