#!/usr/bin/env python # -*- coding: utf-8 -*- # ************************************************************************* # Copyright © 2015 JiangLin. All rights reserved. # File Name: models.py # Author:JiangLin # Mail:[email protected] # Created Time: 2015-11-08 06:42:40 # ************************************************************************* from flask import current_app from maple import db from datetime import datetime tag_blog = db.Table( 'tag_blog', db.Column('tags_id', db.Integer, db.ForeignKey('tags.id')), db.Column('blogs_id', db.Integer, db.ForeignKey('blogs.id'))) class Tags(db.Model): __tablename__ = 'tags' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) blogs = db.relationship( 'Blog', secondary=tag_blog, lazy='dynamic', backref="tags") def __repr__(self): return '<Tags %r>' % self.name def __str__(self): return self.name
# -*- coding=UTF-8 -*- # ************************************************************************** # Copyright © 2016 jianglin # File Name: models.py # Author: jianglin # Email: [email protected] # Created: 2016-07-20 17:00:08 (CST) # Last Update:星期四 2016-7-28 22:30:37 (CST) # By: # Description: # ************************************************************************** from maple import db from datetime import datetime tag_topic = db.Table( 'tag_topic', db.Column('tags_id', db.Integer, db.ForeignKey('tags.id')), db.Column('topics_id', db.Integer, db.ForeignKey('topics.id'))) tags_parents = db.Table( 'tags_parents', db.Column('tag_id', db.Integer, db.ForeignKey('tags.id')), db.Column('parent_id', db.Integer, db.ForeignKey('tags.id'))) class Tags(db.Model): __tablename__ = 'tags' id = db.Column(db.Integer, primary_key=True) time = db.Column(db.DateTime, default=datetime.utcnow()) tagname = db.Column(db.String(64), nullable=False) summary = db.Column(db.Text) tags = db.relationship('Topic', secondary=tag_topic,
#************************************************************************* # Copyright © 2015 JiangLin. All rights reserved. # File Name: articledb.py # Author:JiangLin # Mail:[email protected] # Created Time: 2015-11-29 02:07:53 #************************************************************************* #!/usr/bin/env python # -*- coding=UTF-8 -*- from maple import db from datetime import datetime from flask_login import current_user tag_question = db.Table( 'tag_question', db.Column('tags_id', db.Integer, db.ForeignKey('tags.id', ondelete="CASCADE")), db.Column('questions_id', db.Integer, db.ForeignKey('questions.id', ondelete="CASCADE"))) class Tags(db.Model): __tablename__ = 'tags' '''帖子节点''' id = db.Column(db.Integer, primary_key=True) author = db.Column(db.String(50), nullable=False) name = db.Column(db.String(50), nullable=False) time = db.Column(db.DateTime, nullable=False) __mapper_args__ = {"order_by": time.desc()} def __init__(self, name, author):
#!/usr/bin/env python # -*- coding=UTF-8 -*- # ************************************************************************* # Copyright © 2015 JiangLin. All rights reserved. # File Name: models.py # Author:JiangLin # Mail:[email protected] # Created Time: 2015-11-08 06:42:40 # ************************************************************************* from maple import db from datetime import datetime tag_article = db.Table('tag_article', db.Column('tags_id', db.Integer, db.ForeignKey('tags.id')), db.Column('articles_id', db.Integer, db.ForeignKey('articles.id'))) class Tags(db.Model): __tablename__ = 'tags' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) def __repr__(self): return '<Tags %r>' % self.name @staticmethod def load_by_name(name): return Tags.query.filter_by(name=name).first_or_404()
# Author: jianglin # Email: [email protected] # Created: 2016-07-24 15:10:52 (CST) # Last Update:星期日 2016-7-24 15:11:46 (CST) # By: # Description: # ************************************************************************** from maple import db from maple.tag.models import Tags from datetime import datetime from flask_login import UserMixin from werkzeug.security import (generate_password_hash, check_password_hash) from sqlalchemy import event roles_permissions = db.Table( 'roles_permissions', db.Column('role_id', db.Integer, db.ForeignKey('roles.id')), db.Column('permission_id', db.Integer, db.ForeignKey('permissions.id'))) routes_permissions = db.Table( 'routes_permissions', db.Column('route_id', db.Integer, db.ForeignKey('routes.id')), db.Column('permission_id', db.Integer, db.ForeignKey('permissions.id'))) class Route(db.Model): __tablename__ = 'routes' id = db.Column(db.Integer, primary_key=True) endpoint = db.Column(db.String(256), nullable=False) rule = db.Column(db.String(512), nullable=False) permissions = db.relationship('Permiss', secondary=routes_permissions,
# self.password_hash = generate_password_hash(password) # def verify_password(self, password): # return check_password_hash(password) @staticmethod def set_password(password): pw_hash = generate_password_hash(password) return pw_hash def check_password(self, password): return check_password_hash(self.password, password) roles_parents = db.Table( 'roles_parents', db.Column('role_id', db.Integer, db.ForeignKey('roles.id')), db.Column('parent_id', db.Integer, db.ForeignKey('roles.id'))) class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(81), nullable=False, default='unconfirmed') description = db.Column(db.String(255), nullable=True) parents = db.relationship('Role', secondary=roles_parents, primaryjoin=(id == roles_parents.c.role_id), secondaryjoin=(id == roles_parents.c.parent_id), backref=db.backref('children')) def __str__(self):