-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
39 lines (30 loc) · 1.27 KB
/
models.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
29
30
31
32
33
34
35
36
37
38
39
from sqlalchemy import Column, DateTime, String, Integer, JSON, ForeignKey, Boolean, func
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import class_mapper
from sqlalchemy.orm.properties import ColumnProperty
import db
from datetime import datetime
Base = declarative_base()
Base.metadata.create_all(db.engine)
class BaseMixin(object):
def as_dict(self):
result = {}
for prop in class_mapper(self.__class__).iterate_properties:
if isinstance(prop, ColumnProperty):
result[prop.key] = getattr(self, prop.key)
return result
class ReceivedMessage(BaseMixin, Base):
__tablename__ = 'received_messages'
id = Column(Integer, primary_key=True)
phone_from = Column(String, default=None)
msg_body = Column(String, default=None)
created_at = Column(DateTime, default=datetime.utcnow())
processed_at = Column(DateTime, default=None)
class MessageToSend(BaseMixin, Base):
__tablename__ = 'messages_to_send'
id = Column(Integer, primary_key=True)
phone_to = Column(String, default=None)
msg_body = Column(String, default=None)
created_at = Column(DateTime, default=datetime.utcnow())
sent_at = Column(DateTime, default=None)