示例#1
0
文件: post.py 项目: aksenol/ggkp
from shared import db
from datetime import datetime
from group import Group
from user import User

seen = db.Table(
    'seen', db.Column('user_id', db.Integer, db.ForeignKey('user.user_id')),
    db.Column('post_id', db.Integer, db.ForeignKey('post.post_id')),
    db.Column('time', db.DateTime))


class Post(db.Model):
    post_id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    message = db.Column(db.String(5000))
    url = db.Column(db.String(120))
    settings = db.Column(db.SmallInteger)
    publish_date = db.Column(db.DateTime)
    publisher_id = db.Column(db.Integer, db.ForeignKey('user.user_id'))
    group_id = db.Column(db.Integer, db.ForeignKey('group.group_id'))

    seen_by = db.relationship('User', secondary=seen)
    comments = db.relationship('Comment', backref='post', lazy='dynamic')

    #backrefs
    #publisher -> submitted by
    #group -> submitted in

    def __init__(self, post):
        self.message = post.message
        self.url = post.url
示例#2
0
文件: models.py 项目: Crysflair/FSND
from shared import db

venue_genre = db.Table(
    'venue_genre',
    db.Column('venue_id',
              db.Integer,
              db.ForeignKey('venues.id', ondelete='CASCADE'),
              primary_key=True),
    db.Column('genre_id',
              db.Integer,
              db.ForeignKey('genres.id', ondelete='CASCADE'),
              primary_key=True),
)

artist_genre = db.Table(
    'artist_genre',
    db.Column('artist_id',
              db.Integer,
              db.ForeignKey('artists.id', ondelete='CASCADE'),
              primary_key=True),
    db.Column('genre_id',
              db.Integer,
              db.ForeignKey('genres.id', ondelete='CASCADE'),
              primary_key=True),
)


class Genre(db.Model):
    __tablename__ = 'genres'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    description = db.Column(db.String(100))
示例#3
0
from sqlalchemy import and_
from sqlalchemy.orm import relationship

from model.Post import Post
from model.Poster import Poster
from model.Slip import Slip, slip_from_id
from shared import db

tags = db.Table(
    'tags',
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True),
    db.Column('thread_id',
              db.Integer,
              db.ForeignKey('thread.id'),
              primary_key=True))


class Thread(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    board = db.Column(db.Integer, db.ForeignKey("board.id"), nullable=False)
    views = db.Column(db.Integer, nullable=False)
    posts = relationship("Post", order_by=Post.datetime, cascade="delete")
    last_updated = db.Column(db.DateTime)
    tags = relationship("Tag",
                        secondary=tags,
                        lazy='subquery',
                        backref=db.backref('threads', lazy=True))

    def num_media(self):
        return db.session.query(Post).filter(
            and_(Post.thread == self.id, Post.media != None)).count()
示例#4
0
    author_id = db.Column(db.Integer, db.ForeignKey('authors.id'))
    tags = db.relationship('Tag', secondary='book_tags', backref=db.backref('books', lazy='dynamic'))

    def __init__(self, title,author_id):
        self.title = title
        self.author_id = author_id

    # This is what will be displayed when you examine in the python console
    def __repr__(self):
        return 'id: {}, title: {}, author_id: {}'.format(self.id, self.title, self.author_id)

class Tag(db.Model):
    __tablename__ = 'tags'

    id= db.Column(db.Integer, primary_key=True)
    genre= db.Column(db.Text())

    def __init__(self, genre):
        self.genre = genre

    def __repr__(self):
        return 'id:{} genre: {}'.format(self.id, self.genre)


book_tags = db.Table('book_tags',

    db.Column('id', db.Integer, primary_key=True),
    db.Column('tag_id', db.Integer, db.ForeignKey('tags.id')),
    db.Column('book_id', db.Integer, db.ForeignKey('books.id'))

)
示例#5
0
from shared import db

role_users = db.Table(
    'role_users',
    db.Column(
        'user_id', db.Integer(),
        db.ForeignKey('roles.id', onupdate="CASCADE", ondelete="CASCADE")),
    db.Column(
        'role_id', db.Integer(),
        db.ForeignKey('users.id', onupdate="CASCADE", ondelete="CASCADE")),
)
示例#6
0
from shared import db

post_comments = db.Table(
    'post_comments',
    db.Column(
        'post_id', db.Integer(),
        db.ForeignKey('posts.id', onupdate="CASCADE", ondelete="CASCADE")),
    db.Column(
        'comment_id', db.Integer(),
        db.ForeignKey('comments.id', onupdate="CASCADE", ondelete="CASCADE")))
示例#7
0
from shared import db

post_tags = db.Table(
    'post_tags',
    db.Column(
        'post_id', db.Integer(),
        db.ForeignKey('posts.id', onupdate="CASCADE", ondelete="CASCADE")),
    db.Column('tag_id', db.Integer(),
              db.ForeignKey('tags.id', onupdate="CASCADE",
                            ondelete="CASCADE")),
)
示例#8
0
文件: user.py 项目: aksenol/ggkp
from shared import db
from datetime import datetime

subscribe = db.Table(
    'subscribe', db.Column('user_id', db.Integer,
                           db.ForeignKey('user.user_id')),
    db.Column('group_id', db.Integer, db.ForeignKey('group.group_id')),
    db.Column('time', db.DateTime), db.Column('is_submitter', db.Boolean))

ban = db.Table(
    'ban', db.Column('user_id', db.Integer, db.ForeignKey('user.user_id')),
    db.Column('group_id', db.Integer, db.ForeignKey('group.group_id')),
    db.Column('banned_by', db.Integer, db.ForeignKey('user.user_id')),
    db.Column('time', db.DateTime), db.Column('is_shadow', db.Boolean))


class User(db.Model):
    user_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    first_name = db.Column(db.String(80))
    last_name = db.Column(db.String(80))
    email = db.Column(db.String(80))
    picture = db.Column(db.String(120))
    age_range = db.Column(db.String(80))
    fb_token = db.Column(db.String(120))
    gender = db.Column(db.Integer)
    reg_date = db.Column(db.DateTime)

    posts = db.relationship('Post', backref='publisher', lazy='dynamic')
    subscribed_groups = db.relationship('Group',
                                        secondary=subscribe,
                                        backref=db.backref('subscribers',
示例#9
0
文件: comment.py 项目: aksenol/ggkp
from shared import db
from datetime import datetime
from post import Post

vote = db.Table(
    'vote', db.Column('user_id', db.Integer, db.ForeignKey('user.user_id')),
    db.Column('comment_id', db.Integer, db.ForeignKey('comment.comment_id')),
    db.Column('time', db.DateTime), db.Column('is_upvote', db.Boolean))


class Comment(db.Model):
    comment_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'))
    post_id = db.Column(db.Integer, db.ForeignKey('post.post_id'))
    reply_to = db.Column(db.Integer, db.ForeignKey('comment.comment_id'))
    message = db.Column(db.String(5000))
    publish_date = db.Column(db.DateTime)

    votes = db.relationship('User', secondary=vote)

    #backrefs
    #post

    def __init__(self, comment):
        self.message = comment.message
        self.reply_to = comment.reply_to
        self.user_id = comment.user_id
        self.post_id = comment.post_id
        self.publish_date = datetime.now()

    def __repr__(self):
示例#10
0
# -*- coding: utf-8 -*-
'''
USER MODEL
'''
from flask_security import UserMixin, RoleMixin
from shared import db

# Define the relationship between roles and users
roles_users = db.Table('roles_users',
	db.Column('user_id', db.Integer(), db.ForeignKey('users.id')),
	db.Column('role_id', db.Integer(), db.ForeignKey('roles.id'))
)

# Roles should include users and admins
class Roles(db.Model, RoleMixin):
	__tablename__ = "roles"

	# Primary key
	id = db.Column(db.Integer(), primary_key=True)

	# Columns
	name = db.Column(db.String(80), unique=True)
	description = db.Column(db.String(255))

	# Representation
	def __repr__(self):
		return '<id %r>' % self.id

# Use email as username
class Users(db.Model, UserMixin):
	__tablename__ = 'users'