Event-CRUD-Flask-python3-API/models.py

22 lines
746 B
Python

from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Event(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
description = db.Column(db.String(200))
location = db.Column(db.String(100))
deleted = db.Column(db.Boolean, default=False)
duedate = db.Column(db.DateTime)
created_at = db.Column(db.DateTime, default=db.func.now())
def to_dict(self):
return {
'id': self.id,
'title': self.title,
'description': self.description,
'location': self.location,
'duedate': self.duedate.isoformat() if self.duedate else None,
'created_at': self.created_at.isoformat()
}