コード例 #1
0
class Comment(db.Model):
    id = db.Column(db.Integer , primary_key=True)
    comment = db.Column(db.Text, nullable = False)
    date_commented = db.Column(db.DateTime,nullable=False,default= datetime.utcnow)
    post_id = db.Column(db.Integer,db.ForeignKey('post.id'),nullable=False)
    user_id = db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False)
    def __repr__(self):
        return f"Comment('{self.post_id},{self.user_id},{self.date_commented}')"
コード例 #2
0
class Post(db.Model):
    id = db.Column(db.Integer , primary_key=True)
    title=db.Column(db.String(150),nullable=False)
    date_posted = db.Column(db.DateTime,nullable=False,default= datetime.utcnow)
    content = db.Column(db.Text,nullable = False)
    user_id = db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False)
    comments = db.relationship('Comment',backref='comments',lazy=True)
    def __repr__(self):
        return f"Post('{self.title}',{self.date})"
コード例 #3
0
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 = db.Column(db.String(20),nullable = False,default='default.jpg')
    password = db.Column(db.String(60),nullable = False)
    posts = db.relationship('Post',backref='author',lazy=True)
    comments = db.relationship('Comment',backref='commenter',lazy=True)
    votes =  db.relationship('Post',secondary=vote,backref=db.backref('voters',lazy=True))
    def __repr__(self):
        return f"User('{self.username}',{self.email},{self.image})"
コード例 #4
0
class Tag(db.Model):
    id = db.Column(db.Integer , primary_key=True)
    name = db.Column(db.String(20),unique=True ,nullable = False)
    post_tags =  db.relationship('Post',secondary=post_tag,backref=db.backref('tags',lazy='dynamic'))
    def __repr__(self):
        return f"Tag('{self.name}')"
コード例 #5
0
#db
from csgonews import db, login_manager
from datetime import datetime
from flask_login import UserMixin


@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))
    
post_tag = db.Table('post_tag',
    db.Column('tag_id',db.Integer,db.ForeignKey('tag.id')),
    db.Column('post_id',db.Integer,db.ForeignKey('post.id'))
)

vote = db.Table('vote',
    db.Column('user_id',db.Integer,db.ForeignKey('user.id')),
    db.Column('post_id',db.Integer,db.ForeignKey('post.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 = db.Column(db.String(20),nullable = False,default='default.jpg')
    password = db.Column(db.String(60),nullable = False)
    posts = db.relationship('Post',backref='author',lazy=True)
    comments = db.relationship('Comment',backref='commenter',lazy=True)
    votes =  db.relationship('Post',secondary=vote,backref=db.backref('voters',lazy=True))
    def __repr__(self):