import datetime
from datetime import datetime
import json
from sqlalchemy.exc import IntegrityError
from werkzeug.security import generate_password_hash, check_password_hash
class Tasks(db.Model):
__tablename__ = 'tasks'
# Define the Notes schema
id = db.Column(db.Integer, primary_key=True)
_name = db.Column(db.String(255), unique=False, nullable=False)
_status = db.Column(db.String(255), unique=False, nullable=False)
# Constructor of a Notes object, initializes of instance variables within object
def __init__(self, name, status):
self._name = name
self._status = status
# Returns a string representation of the Notes object, similar to java toString()
# returns string
def __repr__(self):
return "Tasks(" + str(self.id) + "," + self.name + "," + str(self.status) + ")"
# CRUD create, adds a new record to the Notes table
# returns the object added or None in case of an error
def create(self):
try:
# creates a Notes object from Notes(db.Model) class, passes initializers
db.session.add(self) # add prepares to persist person object to Notes table
db.session.commit() # SqlAlchemy "unit of work pattern" requires a manual commit
return self
except IntegrityError:
db.session.remove()
return None
# CRUD read, returns dictionary representation of Notes object
# returns dictionary
def read(self):
return {
"id": self.id,
"name": self.name,
"status": self.status
}