annex.py 2.3 KB
Newer Older
wanli's avatar
wanli committed
1 2
'''
Author: your name
3
Date: 2021-07-15 09:33:39
4
LastEditTime: 2021-07-15 17:10:06
wanli's avatar
wanli committed
5 6
LastEditors: Please set LastEditors
Description: In User Settings Edit
7
FilePath: \evm-store\tools\build_out\models\annex.20210715101849.py
wanli's avatar
wanli committed
8
'''
9 10
#!/usr/bin/env python
# -*- coding: utf_8 -*-
wanli's avatar
wanli committed
11 12 13 14 15 16 17 18 19 20 21

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

class AnnexModel(PrimaryModel):
    __tablename__ = 'evm_annex'

    app = db.Column(db.Integer, nullable = False)
    title = db.Column(db.String(100), index = True, nullable = False, default = '')
    path = db.Column(db.String(256), index = True, nullable = False, default = '')
wanli's avatar
wanli committed
22
    size = db.Column(db.Integer, nullable = True)
wanli's avatar
wanli committed
23 24 25 26 27

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

wanli's avatar
wanli committed
28
    def __init__(self, app, title, path, size, create_by=None, create_at=None, update_by=None, update_at=None):
wanli's avatar
wanli committed
29 30 31 32 33
        self.app = app
        self.title = title
        self.path = path
        self.size = size
        self.create_by = create_by
wanli's avatar
wanli committed
34
        self.create_at = create_at
35
        self.update_by = update_by
wanli's avatar
wanli committed
36 37 38 39 40
        self.update_at = update_at

    def __repr__(self):
        return '<AnnexModel %r>' % (self.app)

41
    def to_dict(self):
wanli's avatar
wanli committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        return {
            'app': self.app,
            'title': self.title,
            'path': self.path,
            'size': self.size,
        }


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


deleteAnnexSchema = DeleteAnnexSchema()

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

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

getListAnnexSchema = GetListAnnexSchema()
getListAnnexsSchema = GetListAnnexSchema(many=True)

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

    app = ma.auto_field()

getAnnexSchema = GetAnnexSchema()