Skip to content

Instantly share code, notes, and snippets.

@robert8138
Last active March 31, 2016 05:06
Show Gist options
  • Save robert8138/7b794877c6fa86cf6d02 to your computer and use it in GitHub Desktop.
Save robert8138/7b794877c6fa86cf6d02 to your computer and use it in GitHub Desktop.
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer, String, Date, Float
db = SQLAlchemy()
class Events(db.Model):
__tablename__ = 'events_full'
id = Column(Integer, primary_key=True)
date = Column(Date)
duration = Column(Float)
event_type = Column(String)
event_name = Column(String)
def __init__(self, date, duration, event_type, event_name):
self.date = date
self.duration = duration
self.event_type = event_type
self.event_name = event_name
@property
def serialize(self):
'''return as a json object so we can use it in RESTful API'''
return {'id': self.id,
'date': self.date.strftime("%Y-%m-%d"),
'duration': self.duration,
'event_type': self.event_type,
'event_name': self.event_name }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment