def save(self): """ Save permission :return: """ db.session.add(self) db.session.commit() role_permissions = db.Table( "role_permissions", db.Column( "permission_id", db.Integer, db.ForeignKey("permissions.id"), primary_key=True, ), db.Column( "role_id", db.Integer, db.ForeignKey("roles.id"), primary_key=True ), ) class RoleModel(db.Model): """ User Role Model """ __tablename__ = "roles" id = db.Column(db.Integer, primary_key=True)
from webapp import db from flask import current_app from flask_login import UserMixin from werkzeug.security import generate_password_hash, check_password_hash import jwt from sqlalchemy import and_, or_, not_ from datetime import datetime, date from time import time # Роли пользователей roles = db.Table('UserRoles', db.Column('user_id', db.Integer, db.ForeignKey('User.id')), db.Column('role_id', db.Integer, db.ForeignKey('Role.id'))) # Пользователи class User(db.Model, UserMixin): __tablename__ = 'User' id = db.Column(db.Integer(), primary_key=True) username = db.Column(db.String(100)) email = db.Column(db.String(100), index=True, unique=True) clinic_id = db.Column(db.Integer(), db.ForeignKey('Clinic.id')) time_create = db.Column(db.DateTime(), default=datetime.utcnow()) password_hash = db.Column(db.String(128)) last_visit = db.Column(db.DateTime(), default=datetime.utcnow()) confirmed = db.Column(db.Boolean(), default=False) roles = db.relationship('Role', secondary=roles, backref=db.backref('users', lazy='dynamic')) def set_password(self, password):
from hashlib import md5 import jwt from flask_login import UserMixin from werkzeug.security import generate_password_hash, check_password_hash from webapp import db, login, app @login.user_loader def load_user(id): return User.query.get(id) followers = db.Table( 'followers', db.Column('follower_id', db.Integer, db.ForeignKey('user.id')), db.Column('followed_id', db.Integer, db.ForeignKey('user.id'))) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) about_me = db.Column(db.String()) last_seen = db.Column(db.DateTime, default=datetime.utcnow()) posts = db.relationship('Post', backref='author', lazy='dynamic') followed = db.relationship('User', secondary=followers, primaryjoin=(followers.c.follower_id == id), secondaryjoin=(followers.c.followed_id == id),
--------------------------- models.py --------------------------- Created on 24.04.2015 Last modified on 13.01.2016 Author: Marc Wieland, Michael Haas Description: Defines the database model ---- ''' from webapp import db from flask_security import RoleMixin, UserMixin from geoalchemy2 import Geometry from sqlalchemy.dialects import postgresql roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('users.users.id')), db.Column('role_id', db.Integer(), db.ForeignKey('users.roles.id')), schema = 'users') class Role(db.Model, RoleMixin): """ Role for database """ __tablename__="roles" __table_args__ = {'schema':'users'} id = db.Column(db.Integer(), primary_key=True) name = '' class User(db.Model, UserMixin): """ User for RRVS
company_details = db.relationship('Companydetail', uselist=False, backref='user') responses = db.relationship('Response', backref='user') def __repr__(self): type = 'student' if self.type == True else 'company' return f"User('{self.username}', '{self.email}', '{type}')" #Many to Many advertisement_studentdetail = db.Table( 'advertisement_studentdetail', db.Column('advertisement_id', db.Integer, db.ForeignKey('advertisement.id'), primary_key=True), db.Column('studentdetail_id', db.Integer, db.ForeignKey('studentdetail.id'), primary_key=True)) studentdetail_keyword = db.Table( 'studentdetail_keyword', db.Column('studentdetail_id', db.Integer, db.ForeignKey('studentdetail.id'), primary_key=True), db.Column('keyword_id', db.Integer, db.ForeignKey('keyword.id'), primary_key=True))
# _*_ coding: utf-8 _*_ # filename: categoryModel.py from webapp import db from datetime import datetime from .blogModel import Blog registrations = db.Table( 'registrations', db.Column('category_id', db.Integer, db.ForeignKey('categorys.id')), db.Column('blog_id', db.Integer, db.ForeignKey('blogs.id'))) class Category(db.Model): __tablename__ = 'categorys' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(128), index=True) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) timestamp = db.Column(db.DateTime, default=datetime.utcnow()) blogs = db.relationship('Blog', secondary=registrations, backref=db.backref('categorys', lazy='dynamic'), lazy='dynamic') # 添加分类 def add_one(self): db.session.add(self) db.session.commit() # 删除分类 def delete_one(self):
#Relationships. These are basically how python does joins. get_author = db.relationship('author_table', backref='written_books', lazy=True) get_publisher = db.relationship('publisher_table', backref='published_books', lazy=True) get_genre = db.relationship('genre_table', secondary = 'genrebook_junctiontable', backref="toBook") class author_table(db.Model): author_id = db.Column(db.Integer, primary_key=True) author_firstname = db.Column(db.String(255)) author_lastname = db.Column(db.String(255)) def __repr__(self): return '<Author FirstName: {} \n Author Lastname: {}'.format(self.author_firstname, self.author_lastname) class publisher_table(db.Model): publisher_id = db.Column(db.Integer, primary_key=True) publisher_name = db.Column(db.String(255)) def __repr__(self): return '<Publisher Id: {} \n Publisher name: {}'.format(self.publisher_id, self.publisher_name) class genre_table(db.Model): genre_id = db.Column(db.Integer, primary_key=True) genre_name = db.Column(db.String(255)) def __repr__(self): return '<Genre Id: {} Genre name: {}\n'.format(self.genre_id, self.genre_name) genrebook_junctiontable = db.Table('genrebook_junctiontable', db.metadata, db.Column('genre_junctionid', db.Integer, db.ForeignKey('genre_table.genre_id')), db.Column('book_junctionid', db.Integer, db.ForeignKey('bookrecord_table.book_id')) )
from flask import abort from flask_sqlalchemy import SQLAlchemy from webapp import db #db = SQLAlchemy() TagRelation = db.Table( 'TagRelation', db.metadata, db.Column('data_id', db.Integer, db.ForeignKey('data.id')), db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))) ## Stores all Tag Names class Tag(db.Model): __tablename__ = "tag" ## The primary Key id = db.Column(db.Integer, primary_key=True) ## The displayed Name name = db.Column(db.String(32), unique=True) #tags = db.relationship(Data, secondary=TagRelation, backref="tags") def __init__(self, name): self.name = name def __repr__(self): return self.name ## Stores all (Meta) Data class Data(db.Model):
from webapp import db, cache from flask_login import AnonymousUserMixin from . import bcrypt class BlogAnonymus(AnonymousUserMixin): def __init__(self): self.email = "Guest" roles = db.Table( "role_user", db.Column("user_id", db.Integer, db.ForeignKey("users.id")), db.Column("role_id", db.Integer, db.ForeignKey("user_roles.id")) ) # User model class User(db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), nullable=False, unique=True) f_name = db.Column(db.String(255), nullable=False) l_name = db.Column(db.String(255)) password = db.Column(db.String(255)) about = db.Column(db.Text()) account_type = db.Column(db.String(25), nullable=False, default="local") email_confirm = db.Column(db.Boolean(), nullable=False, default=False) email_confirm_on = db.Column(db.DateTime()) subscription = db.Column(db.Boolean(), nullable=False, default=False) blocked = db.Column(db.Boolean(), nullable=False, default=False)
class Manufacturer(UserFunctions, db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) Name = db.Column(db.String(80), unique=True) Slug = db.Column(db.String(80), unique=True) Products = db.relationship('Product', backref='Manufacturer') def __repr__(self): return 'Manufacturer: {0} with id: {1}'.format(self.Name, self.id) Order_products = db.Table( 'Order_products', db.Column('Product_id', db.Integer, db.ForeignKey('product.id'), primary_key=True), db.Column('Order_id', db.Integer, db.ForeignKey('order.id'), primary_key=True)) class Order(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) Status = db.Column(db.String) Created = db.Column(db.DateTime, default=datetime.utcnow()) Updated = db.Column(db.DateTime, default=datetime.utcnow(), onupdate=datetime.utcnow()) User_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) Products = db.relationship('Product',
# encoding: utf-8 from sqlalchemy.ext.declarative import declarative_base from webapp import db from flask.ext.security import UserMixin, RoleMixin Base = declarative_base() roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class User(db.Model, UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) sex = db.Column(db.Integer()) firstname = db.Column(db.String(255)) lastname = db.Column(db.String(255)) email = db.Column(db.String(255)) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) class Role(db.Model, RoleMixin): __tablename__ = 'role' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(120), unique=True) description = db.Column(db.String(255))
from dateutil import parser as date_parser from sqlalchemy import and_ from flask import url_for, abort, redirect, request from flask.ext.security.utils import encrypt_password from flask_admin.contrib.sqla import ModelView from flask.ext.security import UserMixin, RoleMixin, current_user from flask_resize import resize from webapp import db, admin, gravatar from webapp.exceptions import DbException from config import Constants from webapp.common import generate_temp_password, random_pwd from assets import strings order_products_table = db.Table('order_products', db.Column('order_id', db.Integer, db.ForeignKey('order.id')), db.Column('product_id', db.Integer, db.ForeignKey('product.id')) ) roles_users_table = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id')) ) class Repopulatable(object): def _is_datetime(self, value): try: return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S') except ValueError: return value
from webapp import db from flask_security import UserMixin, RoleMixin roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db.Model, RoleMixin): """ Roles for authorization. """ id = db.Column(db.Integer(), primary_key=True, unique=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __str__(self): return self.name class User(db.Model, UserMixin): """Authorized Users For the ParseLeads :param str email: email address of user "param str password: encrypted password for the user """ id = db.Column(db.Integer, primary_key=True, unique=True) email = db.Column(db.String, unique=True) password = db.Column(db.String)
import taciturn from webapp import db from sqlalchemy.orm import validates unit_battles = db.Table('unit_battles', db.Column('unit_id', db.Integer, db.ForeignKey('unit.id')), db.Column('battle_id', db.Integer, db.ForeignKey('battle.id')) ) class Unit(taciturn.Unit, db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) speed = db.Column(db.Integer) ct = db.Column(db.Integer) order_num = db.Column(db.Integer) campaign_id = db.Column(db.Integer, db.ForeignKey('campaign.id')) #statuses = [] #slow_action = None def __init__(self, campaign_id, battles=[]): self.campaign_id = campaign_id self.battles = battles def __repr__(self): return '<Unit %s: %s>' % (self.id, self.name) @validates('speed') def validate_speed(self, key, speed): return int(speed)