コード例 #1
0
from flaskr import db

schedule_timeslot = db.Table(
    'schedule_timeslot_association',
    db.Column('time_slot_id', db.Integer, db.ForeignKey('time_slot.id')),
    db.Column('schedule_id', db.Integer, db.ForeignKey('schedule.id')))

instructor_class_schedule = db.Table(
    'instructor_class_schedule_association',
    db.Column('instructor_id', db.Integer, db.ForeignKey('instructor.id')),
    db.Column('class_schedule_id', db.Integer,
              db.ForeignKey('class_schedule.id')))
コード例 #2
0
ファイル: model.py プロジェクト: gabyyan/flask_movieproject
    loginlogs = db.relationship("loginlog", back_populates='userId')
    comments = db.relationship("comment", back_populates='userId')
    collections = db.relationship("collection", back_populates='userId')


class loginlog(db.Model):
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    user_id = db.Column(db.INTEGER, db.ForeignKey('user.id', onupdate="SET NULL", ondelete="SET NULL"), nullable=True)
    userIp = db.Column(db.String(30), nullable=False)
    loginTime = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now())
    userId = db.relationship("user", back_populates='loginlogs')


movie_tag = db.Table('movie_tag',
                     db.Column('tag_id', db.INTEGER, db.ForeignKey('tag.id', ondelete="SET NULL"), nullable=True),
                     db.Column('movie_id', db.INTEGER, db.ForeignKey('movie.id', ondelete="SET NULL"), nullable=True)
                     )


class movie(db.Model):
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    title = db.Column(db.String(30), nullable=False)
    url = db.Column(db.String(600), nullable=False)
    info = db.Column(db.Text, nullable=False)
    logo = db.Column(db.String(50), nullable=False)
    star = db.Column(db.Float, nullable=False)
    playNum = db.Column(db.Integer, nullable=True)
    commentNum = db.Column(db.INTEGER, nullable=True)
    area = db.Column(db.String(50), nullable=False)
    release_time = db.Column(db.Date, nullable=False)
    length = db.Column(db.String(50), nullable=False)
コード例 #3
0
ファイル: models.py プロジェクト: thtay/flask.form
from flaskr import db
from datetime import datetime

subs = db.Table(
    'subs',
    db.Column('design_id', db.Integer, db.ForeignKey('design.design_id')),
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.tag_id')))


class Design(db.Model):
    design_id = db.Column(db.Integer, primary_key=True)
    design_name = db.Column(db.String(40))
    design_content = db.Column(db.String(200))
    date_created = db.Column(db.DateTime, default=datetime.utcnow)
    subscriptions = db.relationship('Tag',
                                    secondary=subs,
                                    backref=db.backref('subscribers',
                                                       lazy='dynamic'))

    def __repr__(self):
        return '<Design {}>'.format(self.design_id)


class Tag(db.Model):
    tag_id = db.Column(db.Integer, primary_key=True)
    tag_name = db.Column(db.String(20))

    def __repr__(self):
        return '<Tag {}>'.format(self.tag_name)
コード例 #4
0
from datetime import datetime
from hashlib import md5
from flaskr import db, login
from flask import current_app
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
import jwt
from time import time

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(UserMixin, db.Model):
    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))
    posts = db.relationship('Post', backref='author', lazy='dynamic')
    about_me = db.Column(db.String(140))
    last_seen = db.Column(db.DateTime, default=datetime.utcnow)
    followed = db.relationship('User',
                               secondary=followers,
                               primaryjoin=(followers.c.follower_id == id),
                               secondaryjoin=(followers.c.followed_id == id),
                               backref=db.backref('followers', lazy='dynamic'),
                               lazy='dynamic')
コード例 #5
0
    username = db.Column(db.String(180), unique=True)
    password = db.Column(db.String(255))
    about = db.Column(db.Text, nullable=True)
    createdAt = db.Column(db.DateTime, default=datetime.utcnow)

    def setpassword(self, password):
        self.password = generate_password_hash(password)

    def checkpassword(self, password):
        return check_password_hash(self.password, password)


posts_tags_association = db.Table(
    'posts_tags',
    db.Column('tag_id', db.Integer, db.ForeignKey('tags.id'),
              primary_key=True),
    db.Column('post_id',
              db.Integer,
              db.ForeignKey('posts.id'),
              primary_key=True))


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

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    user = db.relationship('User', backref=db.backref('posts', lazy=True))
    title = db.Column(db.String(255))
    slug = db.Column(db.String(255))
    text = db.Column(db.Text)
    html = db.Column(db.Text)
コード例 #6
0
from flaskr import db

# Many-to-many table storing Post<->Tags
# YouTube tutorial for many-to-many relationships: https://www.youtube.com/watch?v=OvhoYbjtiKc
posts_to_tags = db.Table(
    'posts_to_tags',
    db.Column('post', db.Integer, db.ForeignKey('post.id')),
    db.Column('tag', db.Integer, db.ForeignKey('tag.id')),
)

# Many-to-many table storing Post<->Image.
posts_to_images = db.Table(
    'posts_to_images',
    db.Column('post', db.Integer, db.ForeignKey('post.id')),
    db.Column('image', db.Integer, db.ForeignKey('image.id')),
)
コード例 #7
0
            print("ADDED FRONTPAGE_POSTS")
        except:
            print("ERROR ADDING TAGS")
            db.session.rollback()

    def _repr_(self):
        return '<{}>'.format(self.title)

    def __str__(self):
        return '<{}>'.format(self.title)


tag_map = db.Table(
    'tag_map', db.Column('tag_id', db.Integer, db.ForeignKey(Tag.id)),
    db.Column('frontpage_post_id', db.Integer,
              db.ForeignKey(Frontpage_post.id)),
    db.Column('job_applicant_id', db.Integer, db.ForeignKey(Job_applicant.id)),
    db.Column('startup_id', db.Integer, db.ForeignKey(Startup.id)),
    db.Column('job_position_id', db.Integer, db.ForeignKey(Job_position.id)))
'''class Tags_map(db.Model):

    __tablename__= 'tags_map'
    id = db.Column(db.Integer, primary_key=True)

    frontpage_post_id = db.Column( db.Integer, db.ForeignKey(Frontpage_post.id))
    tags_id= db.Column( db.Integer, db.ForeignKey(Tag.id))

'''
import click
from flaskr import app
コード例 #8
0
import enum

from flaskr import db, ma
from sqlalchemy.orm import validates
from schema import Schema, And, Or, Regex
from .Base import BaseModel, Column

user_role = db.Table(
    'user_role', Column('user_id', db.String(64), db.ForeignKey('user.id')),
    Column('role_id', db.String(64), db.ForeignKey('role.id')))


class User(BaseModel):
    """ 用户模型
    """
    __tablename__ = "user"

    name = Column("name",
                  db.String(32),
                  nullable=False,
                  comment="名字",
                  validator=(Schema(
                      And(str, lambda v: len(v) >= 3 and len(v) <= 20)),
                             "长度必须3~20位"))
    nickname = Column("nickname", db.String(64), comment="昵称")
    gender = Column("gender",
                    db.SmallInteger,
                    comment="性别",
                    validator=(Schema(lambda v: v in set([0, 1, 2])),
                               "值须为[0, 1, 2]之一"))
    avatar = Column("avatar", db.String(256), comment="头像")