Esempio n. 1
0
class Follower(db.Model):
    __tablename__ = 'follower'
    __table_args__ = (db.PrimaryKeyConstraint('who_id', 'whom_id'), )

    who_id = db.Column(db.Integer)
    whom_id = db.Column(db.Integer)

    def __init__(self, who_id, whom_id):
        self.who_id = who_id
        self.whom_id = whom_id

    def __repr__(self):
        return '<User {0} follows {1}>'.format(self.who_id, self.whom_id)
Esempio n. 2
0
class EventPlayer(db.Model):
    __tablename__ = 'event_players'

    player_id = db.Column(db.Integer,
                          db.ForeignKey('players.id'),
                          primary_key=True)
    event_id = db.Column(db.Integer,
                         db.ForeignKey('events.id'),
                         primary_key=True)
    order = db.Column(db.Integer, nullable=False)
    car_id = db.Column(db.Integer, db.ForeignKey('cars.id'))

    __table_args__ = (db.PrimaryKeyConstraint(player_id, event_id), )

    # Relationships
    car = db.relationship('Car')
Esempio n. 3
0
class StageRanking(db.Model):
    __tablename__ = 'stage_rankings'

    player_id = db.Column(db.Integer,
                          db.ForeignKey('players.id'),
                          primary_key=True)
    stage_id = db.Column(db.Integer,
                         db.ForeignKey('stages.id'),
                         primary_key=True)
    disqualified = db.Column(db.Boolean, nullable=False, default=False)
    points = db.Column(db.Integer, nullable=False, default=0)

    __table_args__ = (db.PrimaryKeyConstraint(player_id, stage_id), )

    # Relationships
    player = db.relationship('Player')
Esempio n. 4
0
from project import app, db
from sqlalchemy_searchable import SearchQueryMixin, make_searchable
from sqlalchemy_utils import UUIDType
from sqlalchemy_utils.types import TSVectorType
from time import time
import uuid

make_searchable()

try:
    if int(os.environ['TESTING']) == 1:
        restaurants_users = db.Table(
            'restaurants_users', db.Column('restaurants_id', db.Integer,
                                           db.ForeignKey('restaurants.id')),
            db.Column('users_id', db.Integer, db.ForeignKey('users.id')),
            db.PrimaryKeyConstraint('restaurants_id', 'users_id'))

        dishes_users = db.Table(
            'dishes_users',
            db.Column('dishes_id', db.Integer, db.ForeignKey('dishes.id')),
            db.Column('users_id', db.Integer, db.ForeignKey('users.id')),
            db.PrimaryKeyConstraint('dishes_id', 'users_id'))
except KeyError:
    restaurants_users = db.Table(
        'restaurants_users',
        db.Column('restaurants_id', UUIDType, db.ForeignKey('restaurants.id')),
        db.Column('users_id', UUIDType, db.ForeignKey('users.id')),
        db.PrimaryKeyConstraint('restaurants_id', 'users_id'))

    dishes_users = db.Table(
        'dishes_users',
Esempio n. 5
0
# backend/project/user/models.py

from project import db, guard
from project.review.models import Review
from project.listing.models import Listing

saved_listings = db.Table(
    'saved_listings', db.Column('user_id', db.Integer,
                                db.ForeignKey('User.id')),
    db.Column('listing_id', db.Integer, db.ForeignKey('Listing.id')),
    db.PrimaryKeyConstraint('user_id', 'listing_id'))


class User(db.Model):
    __tablename__ = 'User'

    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(128), nullable=False)
    last_name = db.Column(db.String(128), nullable=False)
    email = db.Column(db.String(128), nullable=False, unique=True)
    password = db.Column(db.String(256))
    gender = db.Column(db.Text, default='')
    avatar = db.Column(db.Text, default='')
    dob = db.Column(db.DateTime, default=None)
    description = db.Column(db.Text, default='')
    university = db.Column(db.Text)
    verified = db.Column(db.Boolean, nullable=False, default=False)
    listings = db.relationship('Listing', backref='user', lazy=True)
    saved = db.relationship('Listing',
                            secondary=saved_listings,
                            backref=db.backref('saved', lazy='dynamic'))
Esempio n. 6
0
from project import db
from flask.ext.sqlalchemy import SQLAlchemy
from project.media.models import Media

projects_media = db.Table(
    'project_media',
    db.Column('project_id',
              db.Integer,
              db.ForeignKey('projects.id'),
              nullable=False),
    db.Column('media_id',
              db.Integer,
              db.ForeignKey('media.id'),
              nullable=False), db.PrimaryKeyConstraint('project_id',
                                                       'media_id'))


class Project(db.Model):
    __tablename__ = 'projects'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(175), unique=True, nullable=False)
    description = db.Column(db.Text)
    #---------------------------
    region = db.Column(db.Integer, db.ForeignKey('regions.id'))
    district = db.Column(db.Integer, db.ForeignKey('districts.id'))
    subdistrict = db.Column(db.Integer, db.ForeignKey('subdistricts.id'))
    village = db.Column(db.Integer, db.ForeignKey('villages.id'))
    #------------------------------------
    baseline = db.Column(db.Text())
    performance_indicator = db.Column(db.Text)
    budget = db.Column(db.Float())
Esempio n. 7
0
        return self.path


# Many to Many relationship between channels and videos.
# Add Video to Channel: Channel.videos.append(video_id)
# Add Channel to Video: Video.channels.append(channel_id) - Technically redundant.  Don't use.
chan_vid_relationship = db.Table(
    'chan_vid_relationship',
    db.Column('channel_id',
              db.Integer,
              db.ForeignKey('channel.id'),
              nullable=False),
    db.Column('video_id',
              db.Integer,
              db.ForeignKey('video.id'),
              nullable=False), db.PrimaryKeyConstraint('channel_id',
                                                       'video_id'))


class Video(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    filepath = db.Column(db.String(4096))
    first_seen = db.Column(db.DateTime, default=datetime.utcnow())
    last_seen = db.Column(db.DateTime, default=datetime.utcnow())
    active = db.Column(db.Boolean, default=True)
    directory_id = db.Column(db.Integer, db.ForeignKey('directory.id'))

    def __repr__(self):
        return '<File {}>'.format(self.filepath)

    def serialize(self):
        dict = {}
Esempio n. 8
0
from project import db

csmedia = db.Table(
    'cscard_media',
    db.Column('csc_id',
              db.Integer,
              db.ForeignKey('scorecards.id'),
              nullable=False),
    db.Column('media_id',
              db.Integer,
              db.ForeignKey('media.id'),
              nullable=False), db.PrimaryKeyConstraint('csc_id', 'media_id'))


class CSC(db.Model):
    __tablename__ = 'scorecards'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(150))
    description = db.Column(db.Text)
    sector = db.Column(db.Integer, db.ForeignKey('sectors.id'))
    age_from = db.Column(db.Integer)
    age_to = db.Column(db.Integer)
    income_from = db.Column(db.Integer)
    income_to = db.Column(db.Integer)
    budget = db.Column(db.Float)
    date = db.Column(db.DateTime)
    media = db.relationship('Media', secondary=csmedia, backref='scorecards')
    agenda = db.relationship('Agenda',
                             backref='scorecards',
                             cascade='all, delete-orphan',
                             lazy='dynamic')
Esempio n. 9
0
from project import db
from project import bcrypt
from sqlalchemy.orm import relationship
from sqlalchemy import ForeignKey
import datetime

categories_posts = db.Table(
    'categories_posts',
    db.Column('category_id', db.Integer, db.ForeignKey('categories.id')),
    db.Column('post_id', db.Integer, db.ForeignKey('posts.id')),
    db.PrimaryKeyConstraint('post_id', 'category_id'))


class CategoriesPosts(object):
    def __init__(self, category_id, post_id):
        self.post_id = post_id
        self.category_id = category_id


db.mapper(CategoriesPosts, categories_posts)


class BlogPost(db.Model):

    __tablename__ = 'posts'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80), nullable=False)
    description = db.Column(db.Text, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow())
    author_id = db.Column(db.Integer, ForeignKey("users.id"))