예제 #1
0
                        db.ForeignKey('auth_user.id', ondelete='CASCADE'))
    role_id = db.Column(db.Integer(),
                        db.ForeignKey('role.id', ondelete='CASCADE'))


class ContactGroup(db.Model):
    __tablename__ = 'contact_group'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(255))
    owner = db.Column(db.Integer(),
                      db.ForeignKey('auth_user.id', ondelete='CASCADE'))


contact_groups = db.Table(
    'contact_groups',
    db.Column('auth_user_id', db.Integer, db.ForeignKey('auth_user.id')),
    db.Column('contact_group_id', db.Integer,
              db.ForeignKey('contact_group.id')))


class PasswordReset(db.Model):
    __tablename__ = 'password_reset_token'
    id = db.Column(db.Integer(), primary_key=True)
    token = db.Column(db.String(255))
    user = db.Column(db.Integer(), db.ForeignKey('auth_user.id'))
    expire = db.Column(db.Boolean, server_default='0')


class Message(db.Model):
    __tablename__ = 'message'
예제 #2
0
from apps import db

u_consultation = db.Table(
    'u_consultation', db.Column('uid', db.Integer, db.ForeignKey('user.id')),
    db.Column('cid', db.Integer, db.ForeignKey('consultation.id')))

u_activity = db.Table(
    'u_activity', db.Column('uid', db.Integer, db.ForeignKey('user.id')),
    db.Column('aid', db.Integer, db.ForeignKey('activity.id')))

u_tag = db.Table('u_tag', db.Column('uid', db.Integer,
                                    db.ForeignKey('user.id')),
                 db.Column('tid', db.Integer, db.ForeignKey('tag.id')))

a_tag = db.Table('a_tag',
                 db.Column('aid', db.Integer, db.ForeignKey('activity.id')),
                 db.Column('tid', db.Integer, db.ForeignKey('tag.id')))


class User(db.Model):
    """用户表"""
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), default='')
    header_img = db.Column(db.String(100), default='')
    uuid = db.Column(db.String(32), unique=True)
    status = db.Column(db.Boolean, default=True)
    create_time = db.Column(db.DateTime, )
    u_activity = db.relationship('Activity',
                                 secondary=u_activity,
                                 backref=db.backref('users', lazy='dynamic'),
예제 #3
0

#父类
class Base(object):
    creare_time = db.Column(db.DateTime , default=datetime.now())
    update_time = db.Column(db.DateTime , default=datetime.now())

#管理员表
class Admin(Base,db.Model):
    __tablename__ = 'admin'
    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(50),nullable = False)
    pass_hash = db .Column(db.String(200),nullable=False)

table_user_news = db.Table('user_collection',
                           db.Column('id',db.Integer,primary_key=True),
                           db.Column('user_id',db.Integer,db.ForeignKey('user.id')),
                           db.Column('news_id',db.Integer,db.ForeignKey('news.id')))





class User(Base,db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer,primary_key=True)
    nick_name = db.Column(db.String(20),index=True)
    password_has = db .Column(db.String(200),nullable=False)
    mobile = db .Column(db.String(11),nullable=False)
    avatar_url = db.Column(db.String(256))
    last_login = db.Column(db.DateTime)
    signature = db.Column(db.String(512))
예제 #4
0
from apps import db
from jieba.analyse.analyzer import ChineseAnalyzer

article_to_tag = db.Table(
    'article_to_tag',
    db.Column('article_id', db.Integer, db.ForeignKey('article.id')),
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')))


class Article(db.Model):
    __tablename__ = 'article'
    __searchable__ = ['content', 'title']
    __analyzer__ = ChineseAnalyzer()

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    author = db.Column(db.String(32))
    title = db.Column(db.String(32))
    content = db.Column(db.Text)
    tag = db.relationship('Tag',
                          secondary='article_to_tag',
                          backref=db.backref('articles'),
                          lazy='dynamic')
    classify_id = db.Column(db.INTEGER, db.ForeignKey('classify.id'))
    classify = db.relationship('Classify', backref=db.backref('articles'))


class Classify(db.Model):
    __tablename__ = 'classify'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(32))
예제 #5
0
from apps import db
from datetime import datetime

post = db.Table(
    "post",
    db.Column("id", db.Integer, primary_key=True),
    db.Column("article_id", db.Integer, db.ForeignKey("article.id")),
    db.Column("category_id", db.Integer, db.ForeignKey("category.id")),
)


class Article(db.Model):
    __tablename__ = "article"
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(300))
    body = db.Column(db.Text)
    pubDate = db.Column(db.DateTime, default=datetime.now())
    published = db.Column(db.Boolean, nullable=False, default=False)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    category = db.relationship("Category",
                               secondary=post,
                               backref=db.backref("article", lazy="dynamic"))
    counter = db.relationship("Counters", backref="article", lazy=True)


class Category(db.Model):
    __tablename__ = "category"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))

예제 #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import url_for
from flask.ext.sqlalchemy import BaseQuery
from apps.tag.models import Tag
from apps.category.models import Category

from apps import db
from datetime import datetime
from werkzeug import cached_property

article_tags = db.Table('tags',
                        db.Column(
                            'tag_id', db.Integer, db.ForeignKey('tag.id')),
                        db.Column(
                            'post_id', db.Integer, db.ForeignKey('post.id')),
                        )


class PostQuery(BaseQuery):

    def getpost_id(self, id):
        return self.get(id)

    def getall(self):
        return self.all()

    def getpost_byname(self, name):
        return self.filter(Post.post_name.ilike(name)).distinct().first()

    def getpost_perpage(self, pageid, per_page):
    # 将数据转换成 json 格式
    def to_json(self):
        data_json = {"id": self.id, "name": self.name}
        return data_json


# class UserRole(db.Model):
#     __tablename__ = 'tab_user_role',
#     id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 用户编号
#     user_id = db.Column(db.Integer, db.ForeignKey('tab_user.id')),
#     role_id = db.Column(db.Integer, db.ForeignKey('tab_role.id'))

# 用户和角色中间表
tab_user_role = db.Table(
    'tab_user_role',
    db.Column('user_id', db.Integer, db.ForeignKey('tab_user.id')),  # 用户编号
    db.Column('role_id', db.Integer, db.ForeignKey('tab_role.id'))  # 角色编号
)


# 权限表
class Permission(db.Model):
    # 定义表名
    __tablename__ = 'tab_permission'
    # 定义字段
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 用户编号
    name = db.Column(db.String(32))  # 权限名
    code = db.Column(db.String(32))  # 权限编码
    role_id = db.column(db.Integer, db.ForeignKey('tab_role.id'))  # 关联角色表
    menu = db.relationship('Menu',
                           backref='menu',
예제 #8
0
from apps import db
from sqlalchemy import Column, ForeignKey, String, Integer, Table, Text
from sqlalchemy.orm import relationship
from datetime import datetime
from auths import Users

reltags = db.Table(
    'reltags',
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True),
    db.Column('page_id',
              db.Integer,
              db.ForeignKey('posts.id'),
              primary_key=True))


class BlogPost(db.Model):
    __tablename__ = 'posts'

    id = Column(Integer, primary_key=True)
    headline = Column(String(255), nullable=False)
    body = Column(Text)
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)

    user_id = Column(Integer, ForeignKey('users.id'))

    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
    category = db.relationship('Category',
                               backref=db.backref('posts', lazy='dynamic'))

    # many to many BlogPost<->Keyword
    tags = db.relationship('Tag',
예제 #9
0
        return '<Category %r>' % self.category_name


class Changelog(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    log = db.Column(db.Text, nullable=False)
    update_time = db.Column(db.DateTime, nullable=False)
    api_id = db.Column(db.Integer, db.ForeignKey('api.id', ondelete='CASCADE'))

    def __repr__(self):
        return '<Changelog %r>' % self.id


user_api_table = db.Table(
    'user_apis', db.Model.metadata,
    db.Column('id', db.Integer, primary_key=True),
    db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('api_id', db.Integer, db.ForeignKey('api.id')))
"""
user_nitification_table = db.Table('user_notification', db.Model.metadata,
                          db.Column('id', db.Integer, primary_key=True),
                          db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
                          db.Column('changelog_id', db.Integer, db.ForeignKey('changelog.id')),
                          db.Column('read', db.Integer))
"""


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    login_name = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(50), nullable=False)
예제 #10
0
from apps import db
from apps import constants
from apps.utils.base_db import BaseModel
from datetime import datetime
from werkzeug.security import generate_password_hash, check_password_hash

# 用户收藏表,建立用户与其收藏新闻多对多的关系
tb_user_collection = db.Table(
    "info_user_collection",
    db.Column("user_id",
              db.Integer,
              db.ForeignKey("info_user.id"),
              primary_key=True),  # 新闻编号
    db.Column("news_id",
              db.Integer,
              db.ForeignKey("info_news.id"),
              primary_key=True),  # 分类编号
    db.Column("create_time", db.DateTime, default=datetime.now)  # 收藏创建时间
)

tb_user_follows = db.Table(
    "info_user_fans",
    db.Column('follower_id',
              db.Integer,
              db.ForeignKey('info_user.id'),
              primary_key=True),  # 粉丝id
    db.Column('followed_id',
              db.Integer,
              db.ForeignKey('info_user.id'),
              primary_key=True)  # 被关注人的id
)