app = Flask(__name__) moment = Moment(app) app.config.from_object('config') db = SQLAlchemy(app) migrate = Migrate(app,db) # TODO: connect to a local postgresql database #----------------------------------------------------------------------------# # Models. #----------------------------------------------------------------------------# showListings = db.Table('showListings', db.Column('artist_id',db.Integer,db.ForeignKey('Artist.id'),primary_key=True), db.Column('venue_id',db.Integer,db.ForeignKey('Venue.id'),primary_key=True), ) # class showListings(db.Model): # __tablename__='shows' # id = db.Column(db.Integer, primary_key=True) # artist_id= db.Column('artist_id',db.Integer,db.ForeignKey('Artist.id'),primary_key=True) # venue_id=db.Column('venue_id',db.Integer,db.ForeignKey('Venue.id'),primary_key=True) # start_time=db.Column('start_time',db.String(120)) class Venue(db.Model): __tablename__ = 'Venue' id = db.Column(db.Integer, primary_key=True)
### App setup #### ################## manager = Manager(app) db = SQLAlchemy(app) migrate = Migrate(app, db) manager.add_command('db', MigrateCommand) ######################### ##### Set up Models ##### ######################### ## All provided. # Association table on_list = db.Table('on_list', db.Column('item_id', db.Integer, db.ForeignKey('items.id')), db.Column('list_id', db.Integer, db.ForeignKey('lists.id'))) class TodoList(db.Model): __tablename__ = "lists" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(225)) items = db.relationship('TodoItem', secondary=on_list, backref=db.backref('lists', lazy='dynamic'), lazy='dynamic') class TodoItem(db.Model): __tablename__ = "items"
from werkzeug.security import generate_password_hash, check_password_hash from flask_sqlalchemy import SQLAlchemy from datetime import datetime db = SQLAlchemy() # Many to Many - between File and Task files = db.Table('files', db.Column('task_id', db.Integer, db.ForeignKey('task.id'), primary_key=True), db.Column('file_id', db.Integer, db.ForeignKey('file.id'), primary_key=True)) class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(32), unique=True, nullable=False) password = db.Column(db.String(128), nullable=False) admin = db.Column(db.Boolean, default=False, nullable=False) def __init__(self, admin=False, **kwargs): kwargs['name'] = kwargs['name'].lower() kwargs['password'] = generate_password_hash(kwargs['password']) super(User, self).__init__(admin=admin, **kwargs) def __repr__(self): return '<User: %r>' % self.name def set_password(self, password): self.password = generate_password_hash(password) def verify_password(self, password):
return self.role == self.ROLE_STAFF class Course(Base): ======= # 注意这里不再传入 app 了 db = SQLAlchemy() class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(32), unique=True, index=True, nullable=False) publish_courses = db.relationship('Course') created_at = db.Column(db.DateTime, default=datetime.utcnow) updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) class Course(db.Model): >>>>>>> 94eabd4a7886dac73ee0b413078e4000d94daeab __tablename__ = 'course' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), unique=True, index=True, nullable=False) author_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE')) author= db.relationship('User', uselist=False) <<<<<<< HEAD ======= created_at = db.Column(db.DateTime, default=datetime.utcnow) updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) >>>>>>> 94eabd4a7886dac73ee0b413078e4000d94daeab
import sqlite3 from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() association_table = db.Table( 'association', db.Model.metadata, db.Column('user_id', db.Integer, db.ForeignKey('user.id')), db.Column('apartment_id', db.Integer, db.ForeignKey('apartment.id'))) class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) gender = db.Column(db.String, nullable=False) year = db.Column(db.Integer, nullable=False) preferences = db.relationship('Preference', cascade='delete') # liked_apts = db.relationship('Apartment',cascade='delete') apt_matches = db.relationship('Apartment', secondary=association_table, back_populates='user_matches') # apt_id = db.Column(db.Integer,db.ForeignKey('apartment.id'),nullable=False) def __init__(self, **kwargs): self.name = kwargs.get('name', '') #default give '' self.gender = kwargs.get('gender', '') self.year = kwargs.get('year', 1) self.preferences = [] # self.liked_apts=[]
MAIL_USE_SSL=True, MAIL_USERNAME=params['gmail-user'], MAIL_PASSWORD=params['gmail-password']) mail = Mail(app) if (local_server): app.config['SQLALCHEMY_DATABASE_URI'] = params[ 'local_uri'] # "mysql://root:@localhost/flask_tut1" else: app.config['SQLALCHEMY_DATABASE_URI'] = params['prod_uri'] db = SQLAlchemy(app) ########################## 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): id = db.Column(db.Integer, primary_key=True) # name = db.Column(db.String(20)) email = db.Column(db.String(100), unique=True) password = db.Column(db.String(255)) is_admin = db.Column(db.Boolean, default=False) active = db.Column(db.Boolean) confirmed_at = db.Column(db.DateTime) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic'))
from flask_security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin, current_user import random import string import sendgrid from sendgrid.helpers.mail import * app = Flask(__name__) app.config.from_pyfile('config.py') db = SQLAlchemy(app) sg = sendgrid.SendGridAPIClient(apikey=app.config['SENDGRID_API_KEY']) 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): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users,
s_name = db.Column(db.String(10), unique=False, nullable=False) s_age = db.Column(db.Integer, default=19) s_g = db.Column(db.Integer, db.ForeignKey('grade.id'), nullable=True) __tablename__ = 'students' def save(self): db.session.add(self) db.session.commit() class Grade(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) g_name = db.Column(db.Integer, unique=True, nullable=False) students = db.relationship('Students', backref='grade') __tablename__ = 'grade' # 中间表 s_c = db.Table('s_c', db.Column('s_id', db.Integer, db.ForeignKey('students.id')), db.Column('c_id', db.Integer, db.ForeignKey('course.id'))) class Course(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) c_name = db.Column(db.String(30), unique=True, nullable=False) Students = db.relationship('Students', secondary=s_c, backref='cou', lazy='dynamic')
from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() campo_cliente = db.Table( 'campo_cliente', db.Column('campo_id', db.Integer, db.ForeignKey('campo.id')), db.Column('cliente_id', db.Integer, db.ForeignKey('cliente.id'))) class Usuario(db.Model): id = db.Column(db.Integer, primary_key=True) usuario = db.Column(db.String(100), unique=True) contrasena = db.Column(db.String(100)) cargo_id = db.Column(db.Integer, db.ForeignKey("cargo.id")) def as_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} class Cargo(db.Model): id = db.Column(db.Integer, primary_key=True) nombre = db.Column(db.String(100)) usuario = db.relationship('Usuario', cascade="all,delete", backref="cargo") class Servicio(db.Model): id = db.Column(db.Integer, primary_key=True) nombre = db.Column(db.String(100), unique=True) descripcion = db.Column(db.Text) imagenURL = db.Column(db.Text)
app = Flask(__name__) app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' db = SQLAlchemy(app) app.secret_key = "asshd" login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = "login" contributions = db.Table( 'contributions', db.Column('post_id', db.Integer, db.ForeignKey('posts.id'), primary_key=True), db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True)) class Posts(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(140), nullable=False) body = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) created_at = db.Column(db.DateTime, server_default=db.func.now()) updated_at = db.Column(db.DateTime, server_default=db.func.now(),
# init app app = Flask(__name__) basedir = os.path.abspath(os.path.dirname(__file__)) # databse app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, 'db.sqlite') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # init db db = SQLAlchemy(app) # init marshmallow ma = Marshmallow(app) # database model participants = db.Table('participants', db.Column('activity_id', db.Integer, db.ForeignKey( 'activity.id'), primary_key=True), db.Column('user_id', db.Integer, db.ForeignKey( 'user.id'), primary_key=True) ) class Activity(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) type = db.Column(db.String(100), nullable=False) time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) location = db.Column(db.String(10000), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) description = db.Column(db.Text, nullable=False)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) migrate = Migrate(app, db) ma = Marshmallow(app) app.secret_key = "b_5#c]/2Lyz\n\xeF4Q8" EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') INVALID_PASSWORD_REGEX = re.compile( r'^([^0-9]*|[^A-Z]*|[^a-z]*|[^!@#$%^&*()_+=]*)$') bcrypt = Bcrypt(app) likes_table = db.Table( 'likes', db.Column('user_id', db.Integer, db.ForeignKey('users.id'), primary_key=True), db.Column('suggestion_id', db.Integer, db.ForeignKey('suggestions.id'), primary_key=True)) class Users(db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) fname = db.Column(db.String(45)) alias = db.Column(db.String(45)) email = db.Column(db.String(255)) password_hash = db.Column(db.String(60)) created_at = db.Column(db.DateTime, server_default=func.now())
class TodoList(db.Model): __tablename__ = 'todolists' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(), nullable=False) todos = db.relationship('Todo', backref='list', lazy=True) def __repr__(self): return f'<TodoList ID: {self.id}, name: {self.name}, todos: {self.todos}>' order_items = db.Table( 'order_items', db.Column('order_id', db.Integer, db.ForeignKey('order.id'), primary_key=True), db.Column('product_id', db.Integer, db.ForeignKey('product.id'), primary_key=True)) class Order(db.Model): id = db.Column(db.Integer, primary_key=True) status = db.Column(db.String(), nullable=False) products = db.relationship('Product', secondary=order_items, backref=db.backref('orders', lazy=True))
login_manager.session_protection = 'strong' login_manager.login_view = 'login' login_manager.init_app(app) # set up login manager ######################## ######## Models ######## ######################## ## Association tables # NOTE - 364: You may want to complete the models tasks below BEFORE returning to build the association tables! That will making doing this much easier. # NOTE: Remember that setting up association tables in this course always has the same structure! Just make sure you refer to the correct tables and columns! # Look at discussion/lecture exercises tags = db.Table( 'tags', db.Column('gif_id', db.Integer, db.ForeignKey('gifs.id')), db.Column('search_id', db.Integer, db.ForeignKey('search_terms.id'))) user_collection = db.Table( 'user_collection', db.Column('gif_id', db.Integer, db.ForeignKey('gifs.id')), db.Column('collection_id', db.Integer, db.ForeignKey('collections.id'))) ## User-related Models # Special model for users to log in class User(UserMixin, db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255), unique=True, index=True)
id = db.Column(db.Integer(), primary_key=True) username = db.Column(db.String(255)) password = db.Column(db.String(255)) posts = db.relationship('Post', backref='user', lazy='dynamic') def __init__(self, username): self.username = username def __repr__(self): return "<'{}'>".format(self.username) tags = db.Table( 'post_tags', db.Column('post_id', db.Integer(), db.ForeignKey('post.id')), db.Column('tag_id', db.Integer(), db.ForeignKey('tag.id')), ) class Post(db.Model): """Blog Artical Table""" id = db.Column(db.Integer(), primary_key=True) title = db.Column(db.String(255)) text = db.Column(db.Text()) pub_date = db.Column(db.DateTime()) user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) comments = db.relationship('Comments', backref='post', lazy='dynamic') tags = db.relationship('Tags', secondary=tags,
from flask_sqlalchemy import SQLAlchemy from flask_bcrypt import Bcrypt db = SQLAlchemy() bcrypt = Bcrypt() # association table followers = db.Table( 'followers', db.Column('follower_id', db.Integer, db.ForeignKey('users.id')), db.Column('followed_id', db.Integer, db.ForeignKey('users.id'))) class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True) password = db.Column(db.String(120), unique=True) first_name = db.Column(db.String(20), unique=True) last_name = db.Column(db.String(20), unique=True) date = db.Column(db.DateTime) posts = db.relationship('Post', backref='user', lazy='dynamic', cascade="all, delete") # many-to-many followed = db.relationship('User', secondary=followers, primaryjoin=(followers.c.follower_id == id), secondaryjoin=(followers.c.followed_id == id), backref=db.backref('followers', lazy='dynamic'),
author_detail = db.relationship('AuthorDetail', backref='author', uselist=False) def __repr__(self): return '%s(%r)' % (self.__class__.__name__, self.name) class AuthorDetail(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(50)) qq = db.Column(db.String(50)) article_tag = db.Table( 'art_tag', db.Column('art_id', db.Integer, db.ForeignKey('article.id')), db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))) class Article(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(50), nullable=False) author_id = db.Column(db.Integer, db.ForeignKey('author.id')) author = db.relationship('Author', backref='article') tags = db.relationship('Tag', backref='article', secondary=article_tag) class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) tag_title = db.Column(db.String(20), nullable=False)
class Item (db.Model): # saved_item = db.relationship("Item", backref = "user") id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120)) <<<<<<< HEAD # description = db.Column(db.String(2000)) # culture = db.Column(db.String(120)) # climate = db.Column(db.String(120)) # gender = db.Column(db.String(120)) # item_type = db.Column(db.String(120)) # time_period_start = db.Column(db.Integer) # time_period_end = db.Column(db.Integer) owner = db.Column(db.String(120), db.ForeignKey(User.username)) def __init__(self, name, owner): # description, culture, climate, gender, item_type, time_period_start, time_period_end, self.name = name # self.description = description # self.culture = culture # self.climate = climate # self.gender = gender # self.item_type = item_type # self.time_period_end = time_period_start # self.time_period_end = time_period_end self.owner = owner
posts = db.relationship( 'Post', backref='users', lazy='dynamic') def __init__(self, id, username, password): self.id = id self.username = username self.password = password def __repr__(self): """Define the string format for instance of User.""" return "<Model User `{}`>".format(self.username) posts_tags = db.Table('posts_tags', db.Column('post_id', db.String(45), db.ForeignKey('posts.id')), db.Column('tag_id', db.String(45), db.ForeignKey('tags.id'))) class Post(db.Model): """Represents Proected posts.""" __tablename__ = 'posts' id = db.Column(db.String(45), primary_key=True) title = db.Column(db.String(255)) text = db.Column(db.Text()) publish_date = db.Column(db.DateTime) # Set the foreign key for Post user_id = db.Column(db.String(45), db.ForeignKey('users.id')) # Establish contact with Comment's ForeignKey: post_id comments = db.relationship( 'Comment',
import csv from datetime import datetime from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy from werkzeug.security import generate_password_hash, check_password_hash db = SQLAlchemy() migrate = Migrate() orders_meals_association = db.Table( "orders_meals", db.Column("order_id", db.Integer, db.ForeignKey("orders.id")), db.Column("meal_id", db.Integer, db.ForeignKey("meals.id"))) class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer(), primary_key=True) mail = db.Column(db.String(), nullable=False, unique=True) password_hash = db.Column(db.String(128), nullable=False) is_admin = db.Column(db.Boolean(), default=False) orders = db.relationship("Order", back_populates="user") @property def password(self): raise AttributeError("Вам не нужно знать пароль!") @password.setter def password(self, password):
from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() migrate = Migrate() film_studio = db.Table( "film_studio", db.Column("film_id", db.Integer, db.ForeignKey("films.id")), db.Column("studio_id", db.Integer, db.ForeignKey("studios.id"))) class Films(db.Model): id = db.Column(db.Integer, autoincrement=True, primary_key=True) name = db.Column(db.String) year = db.Column(db.String) class Studios(db.Model): id = db.Column(db.Integer, autoincrement=True, primary_key=True) name = db.Column(db.String) films = db.relationship('Films', secondary=film_studio, backref='studio')
class Base(db.Model): __abstract__ = True create_at = db.Column(db.DateTime, default=datetime.utcnow()) update_at = db.Column(db.DateTime, default=datetime.utcnow(), onupdate=datetime.utcnow()) @unique class UserRole(Enum): USER = 10 COMPANY = 20 ADMIN = 30 user_job = db.Table( 'user_job', db.Column('user_id', db.Integer, db.ForeignKey('user.id', ondelete='CASCADE')), db.Column('job_id', db.Integer, db.ForeignKey('job.id', ondelete='CASCADE')) ) # 关联要写大写,也就是说数据表的名称是大写,属性的话用小写 class User(Base, UserMixin): __tablename__ = "user" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(32), unique=True, index=True, nullable=False) email = db.Column(db.String(64), unique=True, index=True, nullable=False) _password = db.Column('password', db.String(256), nullable=False) real_name = db.Column(db.String(20)) phone = db.Column(db.String(11)) work_years = db.Column(db.SmallInteger) role = db.Column(db.SmallInteger, default=UserRole.USER.value)
for i in x.items(): if i[1] > val: clas = i[0] return clas class Topic(db.Model): tablename = 'topic' topic_name = db.Column(db.String(20), primary_key=True) associations = db.Table( 'associate_table', db.Column("left_name", db.String(20), db.ForeignKey("presentation.presentation_name"), primary_key=True), db.Column("right_name", db.String(20), db.ForeignKey("topic.topic_name"), primary_key=True)) person_have_role = db.Table( 'person_have_role', db.Column("user_id", db.Integer(), db.ForeignKey('user.id')), db.Column("role_id", db.Integer(), db.ForeignKey('orm_role.id'))) class User(db.Model, UserMixin): tablename = 'user' id = db.Column(db.Integer, primary_key=True)
from flask import Flask from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def create_app(): app = Flask(__name__) db.init_app(app) return app tags = db.Table('tags', db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True), db.Column('authentication_id', db.Integer, db.ForeignKey('authentication.id'), primary_key=True) , db.Column('authorization_id'), db.Integer, db.ForeignKey('authorization.id'), primary_key=True) class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) pass_hash = db.relationship('Authentication') class Authentication(db.Model): id = db.Column(db.Integer, primary_key=True) pass_hash = db.Column(db.String, nullable=False)
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_login import UserMixin app = Flask(__name__) app.config['SECRET_KEY'] = 'Thisissupposedtobesecret!' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.config['SQLALCHEMY_DATABASE_URI'] = r'sqlite:///db\Litchi.db' db = SQLAlchemy(app) # Many-to-Many Relationships SPORT_MEMBERS = db.Table( 'SPORT_MEMBERS', db.Column('ID_SPORT', db.Integer, db.ForeignKey('SPORT.ID_SPORT')), db.Column('ID_FIGHTER', db.Integer, db.ForeignKey('FIGHTER.ID_FIGHTER'))) # Tabela laczaca zawodnika z walka FIGHTER_FIGHTS = db.Table( 'FIGHTER_FIGHTS', db.Column('ID_FIGHTER', db.Integer, db.ForeignKey('FIGHTER.ID_FIGHTER')), db.Column('ID_FIGHT', db.Integer, db.ForeignKey('FIGHT.ID_FIGHT'))) # # Tabela laczaca zawodnika z menagerem FIGHTER_MANAGER = db.Table( 'FIGHTER_MANAGER', db.Column('ID_FIGHTER', db.Integer, db.ForeignKey('FIGHTER.ID_FIGHTER')), db.Column('ID_MANAGER', db.Integer, db.ForeignKey('MANAGER.ID_MANAGER'))) class USER(UserMixin, db.Model): __tablename__ = 'USER'
login_manager.init_app(app) # set up login manager ######################## ######## Models ######## ######################## ## Association tables # NOTE - 364: You may want to complete the models tasks below BEFORE returning to build the association tables! That will making doing this much easier. # NOTE: Remember that setting up association tables in this course always has the same structure! Just make sure you refer to the correct tables and columns! # TODO 364: Set up association Table between search terms and GIFs (you can call it anything you want, we suggest 'tags' or 'search_gifs'). search_gifs = db.Table( 'search_gifs', db.Column('search_id', db.Integer, db.ForeignKey('search_term.id')), db.Column('gif_id', db.Integer, db.ForeignKey('gifs.id'))) # TODO 364: Set up association Table between GIFs and collections prepared by user (you can call it anything you want. We suggest: user_collection) user_collection = db.Table( 'user_collection', db.Column('user_id', db.Integer, db.ForeignKey('gifs.id')), db.Column('collection_id', db.Integer, db.ForeignKey('personalGifCollections.id'))) ## User-related Models # Special model for users to log in class User(UserMixin, db.Model):
# -*- coding: utf-8 -*- from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() bookmarks_tags = db.Table('bookmarks_tags', db.Column('bookmark_id', db.Integer, db.ForeignKey('bookmark.id')), db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')) ) class Bookmark(db.Model): __tablename__ = 'bookmark' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) reference_id = db.Column(db.Integer, db.ForeignKey('reference.id')) comment = db.Column(db.Text()) rendered_comment = db.Column(db.Text()) isread = db.Column(db.Boolean) star = db.Column(db.Boolean) user = db.relationship("User", back_populates="bookmarks") reference = db.relationship("Reference", back_populates="bookmarks") tags = db.relationship("Tag", secondary=bookmarks_tags, back_populates="bookmarks") def __init__(self, comment): self.comment = comment class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True)
#twitter authntication twitter = Twitter("9jZwbeNcxoRd9BMS2SrRBCNls", "Tbhae7JDjfpDRvb1XFxlCvNB4KIJXgxzOcQzkvqVRY77HDhjqR", "896463626076401664-3j9DGMoxuxFu9OjsXe2iX19R6bhWVkQ", "R0Y4YB4fYQ3CSrDz1Qfj9o4eHB09F2zIwUp1mqi9L1OnE") #print(twitter.get_timeline("zanguejoel")) # Create Flask application app = Flask(__name__) app.config.from_pyfile('config.py') app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER db = SQLAlchemy(app) sockets = Sockets(app) # Define models 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')) ) #check upload file types def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __str__(self): return self.name
# -*- coding: utf-8 -*- from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mssql+pymssql://sa:[email protected]/Product_Test' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True db = SQLAlchemy(app) P_Class_Category = db.Table( 'P_Class_Category', db.Column('P_Class_Id', db.Integer, db.ForeignKey('P_Class.Id')), db.Column('P_Category_Id', db.Integer, db.ForeignKey('P_Category.Id'))) class P_Category(db.Model): __tablename__ = 'P_Category' Id = db.Column(db.Integer, primary_key=True) P_Class_Category = db.relationship('P_Class', secondary=P_Class_Category, backref=db.backref('P_Categorys', lazy='dynamic')) class P_Class(db.Model): Id = db.Column(db.Integer, primary_key=True) if __name__ == "__main__": #db.drop_all()
from time import strftime, time, localtime from datetime import datetime from flask_sqlalchemy import SQLAlchemy from sqlalchemy import Column, Integer, String, Boolean, DateTime, Date db = SQLAlchemy() TipoAtividade = {'minicurso': 0, 'workshop': 1, 'palestra': 2} relacao_atividade_participante = db.Table( 'relacao_atividade_participante', Column('id', Integer, primary_key=True), Column('id_atividade', Integer, db.ForeignKey('atividade.id')), Column('id_participante', Integer, db.ForeignKey('participante.id'))) relacao_atividade_ministrante = db.Table( 'relacao_atividade_ministrante', Column('id', Integer, primary_key=True), Column('id_atividade', Integer, db.ForeignKey('atividade.id')), Column('id_ministrante', Integer, db.ForeignKey('ministrante.id'))) relacao_patrocinador_evento = db.Table( 'relacao_patrocinador_evento', Column('id', Integer, primary_key=True), Column('id_patrocinador', Integer, db.ForeignKey('patrocinador.id')), Column('id_evento', Integer, db.ForeignKey('evento.id'))) relacao_permissao_usuario = db.Table( 'relacao_permissao_usuario', Column('id', Integer, primary_key=True), Column('id_usuario', Integer, db.ForeignKey('usuario.id')), Column('id_permissao', Integer, db.ForeignKey('permissao.id')))