monitorWatch.py 1.35 KB
Newer Older
1 2
#!/usr/bin/env python
# -*- coding: utf_8 -*-
wanli's avatar
wanli committed
3 4 5 6 7 8

from application.app import db, ma
from .base import PrimaryModel 
from marshmallow import Schema, fields, INCLUDE, EXCLUDE

class MonitorWatchModel(PrimaryModel):
9
    __tablename__ = 'evm_monitor_watch'
wanli's avatar
wanli committed
10 11 12 13 14 15 16

    imei = db.Column(db.String(20), index = True, nullable = False, default = '')

    # __table_args__ = (
    #     db.Index('idx_xxx', 'xxx', mysql_using='btree'),
    # )

17
    def __init__(self, imei=''):
wanli's avatar
wanli committed
18 19 20 21 22
        self.imei = imei

    def __repr__(self):
        return '<MonitorWatchModel %r>' % (self.imei)

23
    def to_dict(self):
wanli's avatar
wanli committed
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
        return {
            'imei': self.imei,
        }


class GetListMonitorWatchSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
        unknown = EXCLUDE # 未知字段默认排除
        model = MonitorWatchModel

    page = fields.Integer(required=False)
    pageSize = fields.Integer(required=False)
    imei = ma.auto_field()

getListMonitorWatchSchema = GetListMonitorWatchSchema()
getListMonitorWatchsSchema = GetListMonitorWatchSchema(many=True)

class GetMonitorWatchSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
        unknown = EXCLUDE # 未知字段默认排除
        model = MonitorWatchModel

    imei = ma.auto_field()

getMonitorWatchSchema = GetMonitorWatchSchema()