数据库model自定义字段
2017-06-16 本文已影响0人
樊海鹏
class BIUser(db.Model):
__tablename__ = 'bi_user'
id = db.Column(db.BIGINT, primary_key=True)
user_id = db.Column(db.BIGINT, unique=True, nullable=False, index=True)
username = db.Column(db.String(255), index=True)
og_account = db.Column(db.String(255), index=True)
facebook_id = db.Column(db.String(255))
email = db.Column(db.String(255), index=True)
email_validate_time = db.Column(OGInsertableAwareDateTime, index=True)
email_promotion_allowed = db.Column(db.Boolean)
account_status = db.Column(db.String(255))
class OGInsertableAwareDateTime(types.TypeDecorator):
impl = ArrowType
# def process_bind_param(self, value, _):
# if value is not None:
# if isinstance(value, datetime):
# return arrow.get(value).replace(hours=-8).to(app.config['APP_TIMEZONE'])
# return arrow.get(value).replace(hours=-8).to(app.config['APP_TIMEZONE'])
def process_bind_param(self, value, _):
if value is not None:
return arrow.get(value).replace(hours=-8)
def process_result_value(self, value, _):
if value is not None:
return value.to(app.config['APP_TIMEZONE']