-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
52 lines (35 loc) · 1.23 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
40
41
42
43
44
45
46
47
48
49
50
51
52
import enum
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy import func
from sqlalchemy.ext.declarative import AbstractConcreteBase
from sqlalchemy.ext.declarative import declared_attr
db = SQLAlchemy()
class Base(db.Model):
__abstract__ = True
@declared_attr
def __tablename__(cls):
return cls.__name__.lower()
id = db.Column(db.Integer, primary_key=True)
class TimestampMixin(object):
created_on = db.Column(db.DateTime, server_default=func.now())
updated_on = db.Column(db.DateTime, server_default=func.now(),
onupdate=func.now())
class TicketStatus(enum.Enum):
open = 'open'
in_progess = 'in_progress'
rejected = 'rejected'
closed = 'closed'
all = (open, in_progess, rejected, closed)
class Ticket(AbstractConcreteBase, TimestampMixin, Base):
status = db.Column(db.Enum(TicketStatus), nullable=False,
default=TicketStatus.open)
@declared_attr
def __mapper_args__(cls):
if cls == Ticket:
return {'concrete': False}
return {
'polymorphic_identity': cls.__name__,
'concrete': True
}
class TestTicket(Ticket):
data = db.Column(db.String, nullable=False)