Beispiel #1
0
class Room(BaseModel):

    name = db.Column(db.String(64), default='匿名聊天室')
    url = db.Column(db.String(255))

    host_id = db.Column(db.Integer, nullable=True)
    users = db.relationship('User', secondary='u_r', backref='rooms')

    messages = db.relationship('Message', backref='m_room', cascade='all')

    __tablename__ = 'room'


class Message(BaseModel):
    body = db.Column(db.Text, nullable=False)
    timestamp = db.Column(db.DateTime, default=datetime.now(), index=True)

    message_author = db.Column(db.Integer,
                               db.ForeignKey('user.id'),
                               nullable=False)
    message_room = db.Column(db.Integer,
                             db.ForeignKey('room.id'),
                             nullable=False)


u_r = db.Table(
    'u_r',
    db.Column('u_id', db.Integer, db.ForeignKey('user.id'), primary_key=True),
    db.Column('r_id', db.Integer, db.ForeignKey('room.id'), primary_key=True),
)
Beispiel #2
0
            'id_name': self.id_name,
            'id_card': self.id_card
        }

    def to_basic_dict(self):
        return {
            'id': self.id,
            'avatar': self.avatar if self.avatar else '',
            'name': self.name,
            'phone': self.phone
        }


ihome_house_facility = db.Table(
    'ihome_house_facility',
    db.Column('house_id', db.Integer, db.ForeignKey('ihome_house.id'), primary_key=True),  # 房屋编码
    db.Column('facility_id', db.Integer, db.ForeignKey('ihome_facility.id'), primary_key=True)  # 设施编号
)


class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ihome_house"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号
    # 房屋主人的用户编号
    user_id = db.Column(db.Integer, db.ForeignKey("ihome_user.id"), nullable=False)
    # 归属地的区域编号
    area_id = db.Column(db.Integer, db.ForeignKey("ihome_area.id"), nullable=False)
    title = db.Column(db.String(64), nullable=False)  # 标题
Beispiel #3
0
from datetime import datetime
from App.ext import db
from marshmallow import Schema, fields

# 多对多 角色与权限关系表
from App.model.auth import AuthSchema

role_auth = db.Table(
    'role_auth',
    db.Column('role_id', db.Integer, db.ForeignKey('role.id'), primary_key=True),
    db.Column('auth_id', db.Integer, db.ForeignKey('auth.id'), primary_key=True)
)


class Role(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    role_name = db.Column(db.String(32), unique=True, nullable=False)  # 角色名称
    depict = db.Column(db.String(255))  # 描述
    is_root = db.Column(db.Integer, default=0, nullable=False)  # 是否是系统内置 0.否 1.是
    status = db.Column(db.Integer, default=1)  # 角色状态 1.启用  0.禁用
    update_time = db.Column(db.DateTime, default=datetime.utcnow())  # 更新时间
    create_time = db.Column(db.DateTime, default=datetime.utcnow())  # 创建时间
    auth_list = db.relationship("Auth", backref=db.backref('roles'), secondary=role_auth, lazy="dynamic")  # 角色

    def to_json(self):
        ret = self.__dict__
        if "_sa_instance_state" in ret:
            del ret["_sa_instance_state"]
        return ret

Beispiel #4
0
from datetime import datetime
from werkzeug.security import generate_password_hash, check_password_hash
from App.ext import db
from marshmallow import Schema, fields
from App.model.role import RoleSchema

AVATAR = "https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png"

# 多对多 用户与角色关系表
user_role = db.Table(
    'user_role',
    db.Column('user_id',
              db.Integer,
              db.ForeignKey('user.id'),
              primary_key=True),
    db.Column('role_id',
              db.Integer,
              db.ForeignKey('role.id'),
              primary_key=True))


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(32), nullable=False)  # 用户名称
    password_hash = db.Column(db.String(255), nullable=False)  # 加密后的密码
    mobile = db.Column(db.String(11))  # 手机号码
    avatar = db.Column(db.String(255), default=AVATAR)  # 用户头像
    create_time = db.Column(db.DateTime, default=datetime.utcnow())  # 创建时间
    update_time = db.Column(db.DateTime, default=datetime.utcnow())  # 更新时间
    last_login = db.Column(db.DateTime, default=datetime.utcnow())  # 最后登录时间
    status = db.Column(db.Integer, default=1)  # 状态  0.禁用 1.启用 -1.删除
Beispiel #5
0
    __tablename__ = 'user'

    def __init__(self, username, password):
        self.username = username
        self.password = password

    def save(self):
        db.session.add(self)
        db.session.commit()


r_p = db.Table(
    'r_p',
    db.Column('role_id',
              db.Integer,
              db.ForeignKey('role.r_id'),
              primary_key=True),
    db.Column('permission_id',
              db.Integer,
              db.ForeignKey('permission.p_id'),
              primary_key=True))


class Role(db.Model):
    r_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    r_name = db.Column(db.String(10))
    users = db.relationship('User', backref='role')

    __tablename__ = 'role'

    def __init__(self, r_name):
        self.r_name = r_name
Beispiel #6
0
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    c_num = db.Column(db.Integer)
    is_choosed = db.Column(db.Boolean, default=True)
    ordermodel = db.relationship('OrderModel',
                                 secondary='registrations',
                                 backref=db.backref('orders'),
                                 lazy='dynamic')
    __name__ = "App_cartmodel"


class OrderModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    o_num = db.Column(db.String(250), unique=True)
    is_pay = db.Column(db.Integer)
    __name__ = "App_ordermodel"


registrations = db.Table('App_ordergoodsmodel',
                         db.Column('orderid', db.Integer,
                                   db.ForeignKey('App_ordermodel.id')),
                         db.Column('goodsid', db.Integer,
                                   db.ForeignKey('App_cartmodel.id')),
                         goods_num=db.Column(db.Integer, default=1))

# class OrderGoodsModel(models.Model):
#     orderid=models.ForeignKey(OrderModel)
#     goodsid = models.ForeignKey(MainGoods)
#
#     goods_num = db.Column(db.Integer,default=1)
Beispiel #7
0
    name = db.Column(db.String(16))
    address = db.relationship('Address', backref='person',
                              lazy='dynamic')  # 声明关系   backref


class Address(db.Model, ModelBase):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(64))
    person_id = db.Column(db.Integer, db.ForeignKey('person.id'))


# many to many

#  辅表
tags = db.Table('tags', db.Column('tag_id', db.Integer,
                                  db.ForeignKey('tag.id')),
                db.Column('page_id', db.Integer, db.ForeignKey('page.id')))


class Page(db.Model, ModelBase):
    id = db.Column(db.Integer, primary_key=True)
    tags = db.relationship('Tag',
                           secondary=tags,
                           backref=db.backref('pages', lazy='dynamic'))


class Tag(db.Model, ModelBase):
    id = db.Column(db.Integer, primary_key=True)


class News(db.Model, ModelBase):