コード例 #1
0
ファイル: models.py プロジェクト: and718/My_coding
class Role(db.Model):
    __tablename__ = "t_role"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), unique=True, nullable=False)
    desc = db.Column(db.String(64))

    users = db.relationship('User', backref='role')
    menus = db.relationship('Menu', secondary=trm)

    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'desc': self.desc,
            'menu': self.get_menu_dict()
        }

    def get_menu_dict(self):
        menu_list = []
        menus = sorted(self.menus, key=lambda temp: temp.id)
        for m in menus:
            if m.level == 1:
                first_dict = m.to_dict()
                first_dict['children'] = []
                for s in menus:
                    if s.level == 2 and s.pid == m.id:
                        first_dict['children'].append(s.to_dict())
                menu_list.append(first_dict)
        return menu_list
コード例 #2
0
ファイル: models.py プロジェクト: and718/My_coding
class Menu(db.Model):
    __tablename__ = 't_menu'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), unique=True, nullable=False)
    level = db.Column(db.Integer)
    path = db.Column(db.String(32))

    pid = db.Column(db.Integer, db.ForeignKey('t_menu.id'))
    children = db.relationship('Menu')
    roles = db.relationship('Role', secondary=trm)

    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'level': self.level,
            'path': self.path,
            'pid': self.pid
        }

    def get_children_list(self):
        obj_children = self.children
        data = []
        for o in obj_children:
            data.append(o.to_dict())
        return data
コード例 #3
0
ファイル: models.py プロジェクト: and718/My_coding
class Order(db.Model, BaseModel):
    __tablename__ = 't_order'
    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, db.ForeignKey('t_table.id'))
    price = db.Column(db.Float)

    number = db.Column(db.Integer)
    pay_status = db.Column(db.Integer)  # 0 没支付,1 已支付
    is_send = db.Column(db.Integer)  # 0 没发送,1 已发送
    fapiao_title = db.Column(db.String(32))
    fapiao_company = db.Column(db.String(128))
    fapiao_content = db.Column(db.String(521))
    addrs = db.Column(db.String(521))

    user = db.relationship('User', foreign_keys=[uid])
    order_detail = db.relationship('OrderDetail', backref='order')
    express = db.relationship('Express', backref='order')

    def to_dict(self):
        return {
            'id': self.id,
            'uid': self.uid,
            'uname': self.user.nick_name,
            'price': self.price,
            'number': self.number,
            'pay_status': self.pay_status,
            'is_send': self.is_send,
            'fapiao_title': self.fapiao_title,
            'fapiao_content': self.fapiao_content,
            'addrs': self.addrs
        }
コード例 #4
0
ファイル: models.py プロジェクト: and718/My_coding
class Category(db.Model):
    __tablename__ = 't_category'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), nullable=False)
    level = db.Column(db.Integer)
    pid = db.Column(db.Integer, db.ForeignKey('t_category.id'))

    children = db.relationship('Category')
    attr = db.relationship('Attribute', backref='category')

    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'level': self.level,
            'pid': self.pid,
        }
コード例 #5
0
ファイル: models.py プロジェクト: and718/My_coding
class Goods(db.Model):
    __tablename__ = 't_goods'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(512))
    price = db.Column(db.Float)
    number = db.Column(db.Integer)
    introduce = db.Column(db.Text)
    big_log = db.Column(db.String(256))
    small_log = db.Column(db.String(256))
    state = db.Column(db.Integer)  # 0 未通过 1 审核中 2 已审核
    is_promate = db.Column(db.Integer)
    hot_number = db.Column(db.Integer)
    weight = db.Column(db.Integer)
    cid_one = db.Column(db.Integer, db.ForeignKey('t_category.id'))
    cid_two = db.Column(db.Integer, db.ForeignKey('t_category.id'))
    cid_three = db.Column(db.Integer, db.ForeignKey('t_category.id'))
    category = db.relationship('Category', foreign_keys=[cid_three])

    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'price': self.price,
            'number': self.number,
            'introduce': self.introduce,
            'big_log': self.big_log,
            'small_log': self.small_log,
            'state': self.state,
            'is_promate': self.is_promate,
            'hot_number': self.hot_number,
            'weight': self.weight,
            'cid_one': self.cid_one,
            'cid_two': self.cid_two,
            'cid_three': self.cid_three,
            'attr': [a.to_dict() for a in self.category.attr]
        }