-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodels.py
29 lines (21 loc) · 939 Bytes
/
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
from database import db
from datetime import datetime
from utils import random_hex_32
def _default_repr(class_obj):
return "<%s>" % ", ".join(["%s:%s" % i for i in sorted(list(class_obj.__dict__.items()), key=lambda x: x[0])])
class QA(db.Model):
id = db.Column(db.INTEGER, primary_key=True)
question = db.Column(db.Text, nullable=False)
answer = db.Column(db.Text, default=None)
question_timestamp = db.Column(db.DateTime, default=datetime.now)
answer_timestamp = db.Column(db.DateTime, default=None)
is_public = db.Column(db.Boolean, nullable=True, default=False)
secret = db.Column(db.String, default=random_hex_32)
def __repr__(self):
return _default_repr(self)
class Likes(db.Model):
id = db.Column(db.INTEGER, primary_key=True)
QA_id = db.Column(db.INTEGER, default=0)
likes = db.Column(db.INTEGER, default=0)
def __repr__(self):
return _default_repr(self)