from flaskapp import db from datetime import datetime like = db.Table('like', db.Column('authorid', db.String, db.ForeignKey('user.userid')), db.Column('imageid', db.Integer, db.ForeignKey('image.id'))) class User(db.Model): id = db.Column(db.Integer, primary_key=True) userid = db.Column(db.String, nullable=False, unique=True) username = db.Column(db.String, index=True, nullable=False) images = db.relationship('Image', backref='author', lazy='dynamic') likes = db.relationship('Image', secondary=like, backref='liker', lazy='dynamic') def __repr__(self): return '<User {}>'.format(self.username) class Image(db.Model): id = db.Column(db.Integer, primary_key=True) authorid = db.Column(db.String, db.ForeignKey('user.userid'), nullable=False) created = db.Column( db.DateTime, index=True, default=datetime.utcnow,
from datetime import datetime from flask import current_app as app from flaskapp import db from flaskapp.utils import delete_image, save_image likes = db.Table( 'likes', db.Column('profile_id', db.Integer, db.ForeignKey('profile.id'), primary_key=True), db.Column('post_id', db.Integer, db.ForeignKey('post.id'), primary_key=True), db.Column('date_liked', db.DateTime, nullable=False, default=datetime.utcnow), ) class Post(db.Model): id = db.Column(db.Integer, primary_key=True) author_id = db.Column(db.Integer, db.ForeignKey('profile.id', ondelete='CASCADE'), nullable=False) content = db.Column(db.String(280), nullable=False) location = db.Column(db.String(40), nullable=True)
def load_user(user_id): return User.query.get(int(user_id)) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) authors = db.Table( 'author_relations', db.Column('book_id', db.Integer, db.ForeignKey('books.id')), db.Column('author_id', db.Integer, db.ForeignKey('author.author_id'))) categories = db.Table( 'category_relations', db.Column('book_id', db.Integer, db.ForeignKey('books.id')), db.Column('category_id', db.Integer, db.ForeignKey('category.category_id'))) class Books(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) authors = db.relationship('Author', secondary=authors, backref=db.backref('authors', lazy='dynamic'))
name=card['name'], power=card['power'], toughness=card['toughness'], manaCost=card['manaCost'] # image=card['imageUrl'] # card_types=card['types'], # card_sub_type=card['subtypes'] ) cardList.append(new_entry) db.session.add_all(cardList) db.session.commit() user_card_assoc = db.Table( 'card_user_assoc', db.Column('user_id', db.Integer, db.ForeignKey('user.id')), db.Column('card_id', db.Integer, db.ForeignKey('card.id'))) card_type_assoc = db.Table( 'card_type_assoc', db.Column('card_id', db.Integer, db.ForeignKey('card.id')), db.Column('card_type', db.Integer, db.ForeignKey('card_type.id'))) card_sub_type_assoc = db.Table( 'card_sub_type_assoc', db.Column('card_id', db.Integer, db.ForeignKey('card.id')), db.Column('card_type', db.Integer, db.ForeignKey('card_sub_type.id'))) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True)
from flaskapp import db, login_manager from flask_login import UserMixin @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) user_card_assoc = db.Table( 'user_card_assoc', db.Column('card_id', db.Integer, db.ForeignKey('card.id')), db.Column('user_id', db.Integer, db.ForeignKey('user.id'))) class User(db.Model, UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) cards = db.relationship('Card', secondary=user_card_assoc, backref=db.backref('owners', lazy='dynamic')) def __repr__(self): return 'User:' + self.username
from datetime import datetime from sqlalchemy.orm import backref from flaskapp import db, login_manager from flask_login import UserMixin import timeago import random @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) followers = db.Table( 'followers', db.Column('user_id', db.Integer, db.ForeignKey('users.uid')), db.Column('follows_id', db.Integer, db.ForeignKey('users.uid'))) likes = db.Table('likes', db.Column('post_id', db.Integer, db.ForeignKey('posts.pid')), db.Column('user_id', db.Integer, db.ForeignKey('users.uid'))) class User(db.Model, UserMixin): __tablename__ = 'users' uid = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(32), nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
subject = 'Password Reset Request' send_email(self.email, subject, html) def verify_password(self, password_to_verify): return bcrypt.check_password_hash(self.password, password_to_verify) def __repr__(self): return f"User({self.id}, '{self.email}', '{self.username}', '{self.password}')" def __str__(self): return f"User(#{self.id}, '{self.username}')" followers = db.Table( 'followers', db.Column('follower_id', db.Integer, db.ForeignKey('profile.id')), db.Column('followed_id', db.Integer, db.ForeignKey('profile.id')), ) class Profile(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), nullable=False) bio = db.Column(db.String(300), nullable=True) city = db.Column(db.String(100), nullable=True) website = db.Column(db.String(40), nullable=True) # Users have to have at least default img, so nullable=False. image = db.Column(db.String(20), nullable=False, default='default.jpg') posts = db.relationship('Post',
from flask_login import UserMixin from flaskapp import db, login_manager user_role = db.Table( 'user_role', db.Column('emp_id', db.Integer, db.ForeignKey('employees.emp_id'), primary_key=True), db.Column('role_id', db.Integer, db.ForeignKey('roles.role_id'), primary_key=True)) class Employee(db.Model, UserMixin): __tablename__ = 'employees' emp_id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), unique=True, nullable=False) email = db.Column(db.String(64), unique=True, nullable=False) firstname = db.Column(db.String(64), nullable=False) lastname = db.Column(db.String(64), nullable=False) password = db.Column(db.String(64), nullable=False) dept_id = db.Column(db.Integer, db.ForeignKey('departments.dept_id')) is_leader = db.Column(db.Boolean, default=False) rel_roles = db.relationship('Role', secondary=user_role, backref=db.backref('employee', lazy='dynamic')) def get_id(self):
from flaskapp import db, login_manager from flask_login import UserMixin """ All Model classes represent tables within the database. Primary keys are represented by primary_key=True. Foreign keys are represented by db.ForeignKey. Several bridging tables exist to break up many to many relationships, E.g. AnimeSeries - AnimeGenre - Genre """ @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) favorites = db.Table( 'favorites', db.Column('user_id', db.Integer, db.ForeignKey('user.id')), db.Column('animeseries_id', db.Integer, db.ForeignKey('animeseries.id'))) class UserPassList(db.Model): user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) animeseries_id = db.Column(db.Integer, db.ForeignKey('animeseries.id'), primary_key=True) def __repr__(self): return f"{self.animeseries_id}" class UserRating(db.Model): user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
from datetime import datetime from flaskapp import db, login_manager from flask_login import UserMixin @login_manager.user_loader def load_user(userId): return User.query.get(int(userId)) subs = db.Table('subs', db.Column('course_id', db.Integer, db.ForeignKey('course.id')), db.Column('user_id', db.Integer, db.ForeignKey('user.id'))) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) firstname = db.Column(db.String(60), nullable=False) lastname = db.Column(db.String(60), nullable=False) email = db.Column(db.String(60), nullable=False) dob = db.Column(db.Date, nullable=False) password = db.Column(db.String(60), nullable=False) number = db.Column(db.String(13), nullable=False) confirmed = db.Column(db.Boolean, default=False, nullable=False) admin = db.Column(db.Boolean, default=False, nullable=False) courses = db.relationship('Course', secondary=subs, lazy='dynamic', backref=db.backref('subscribers', lazy=True)) answer = db.relationship('Ans', backref=db.backref('author'), lazy=True)
from datetime import datetime import pytz from flaskapp.model.User import User from flaskapp.model.Operator import * from sqlalchemy.ext.associationproxy import association_proxy # from flaskapp import mamake from marshmallow import fields, Schema #For a time being putting all inside the same file first - seperate the class later def sgtimestampnow(): return datetime.now(pytz.timezone('Asia/Singapore')) #incident has emergencyType M2M relationship table incident_has_emergencyType = db.Table('incident_has_emergencyType', db.Column('eid', db.Integer, db.ForeignKey('emergency_type.eid')), db.Column('incidentID', db.Integer, db.ForeignKey('incident.incidentID')) ) class EmergencyType(db.Model): __tablename__ = 'emergency_type' eid = db.Column(db.Integer, primary_key=True) emergencyName = db.Column(db.String(30), unique=True, nullable=False) def __init__(self, **kwargs): super(EmergencyType, self).__init__(**kwargs) #request M2M relationship table incident_request_assistanceType = db.Table('incident_request_assistanceType',