-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
29 lines (20 loc) · 764 Bytes
/
models.py
File metadata and controls
29 lines (20 loc) · 764 Bytes
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
import datetime
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Todo(db.Model):
id = db.Column(db.Integer, primary_key=True, nullable=False)
task = db.Column(db.String(100), nullable=False)
description = db.Column(db.String(500), nullable=True)
created = db.Column(db.DateTime, default=datetime.datetime.utcnow)
def __str__(self):
return "<Todo: {}>".format(self.task)
def converter(self, obj):
if isinstance(obj, datetime.datetime):
return obj.__str__()
def json_serialize(self):
todo = {}
todo["id"] = self.id
todo["task"] = self.task
todo["description"] = self.description
todo["created"] = self.converter(self.created)
return todo