예제 #1
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    project_id = db.Column(db.Integer,
                           db.ForeignKey('project.id'),
                           nullable=False)

    def __repr__(self):
        return "Post('{}','{}','{}')".format(self.title, self.date,
                                             self.user_id)
예제 #2
0
class Project(db.Model):
    contributors = db.relationship('User',
                                   secondary='contributor_table',
                                   backref='contribution_id')

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    github_repo = db.Column(db.String(120), nullable=True, unique=True)
    admin_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    tag = db.Column(db.String, nullable=True)

    def __repr__(self):
        return "Project('{}','{}','{}')".format(self.title, self.date,
                                                self.content)
예제 #3
0
from datetime import datetime

from flask import current_app
from flask_login import UserMixin
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer

from tbcompanion import db, login_man

contributor_table = db.Table(
    'contributor_table',
    db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('project_id', db.Integer, db.ForeignKey('project.id')))


@login_man.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))


class User(db.Model, UserMixin):
    post_author = db.relationship('Post', backref='author', lazy=True)
    project_admin = db.relationship('Project', backref='admin', lazy=True)

    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='profile_pics\default.jpg')
    password = db.Column(db.String(60), nullable=False)
    is_admin = db.Column(db.Boolean)