예제 #1
0
class Reply(db.Model):
    id=db.Column(db.Integer, primary_key=True)
    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)
    comment_id=db.Column(db.Integer, db.ForeignKey('comment.id'), nullable=False)
    
    def __repr__(self):
        return f"Reply('{self.author.username}')"
예제 #2
0
class File(db.Model):
    __searchable__= ['title']
   
    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)
    data=db.Column(db.String(220), nullable=False)
    user_id=db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
    description=db.Column(db.String(500), nullable=False)
    category=db.Column(db.String(20), nullable=False)
    cover=db.relationship('Cover', backref='file', lazy='dynamic', cascade='all, delete-orphan')
    downloaded=db.Column(db.Integer, default=0)
    _img_id=db.Column(db.Integer, default=0)
    img_id=_img_id
    file_size=db.Column(db.String(10), nullable=True)
    auteur=db.Column(db.String(100), nullable=True)
    extend_existing=True


    def _set_img(self, id):
        self._img_id=id

    def downloads(self):
        self.downloaded+=1
    

    def __repr__(self):
        return f"File('{self.title}', '{self.date_posted}')"    

    _img_id=property(_set_img)
예제 #3
0
class Comment(db.Model):
    id=db.Column(db.Integer, primary_key=True)  
    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)
    post_id=db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False)
    reply=db.relationship('Reply', backref='comment', lazy='dynamic', cascade='all, delete-orphan')
    nbrep=db.Column(db.Integer, default=0)

    @property
    def rep(self):
        return self.nbrep

    @rep.setter
    def rep(self, rep):
        self.nbrep+=rep    
예제 #4
0
class Ebook(db.Model):
    id=db.Column(db.Integer, primary_key=True)
    user_id=db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    date_posted=db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title=db.Column(db.String(40), nullable=False)
    author=db.Column(db.String(40), nullable=False)

    def __repr__(self):
        return f"Ebook('{self.title}', '{self.date_posted}')"    
예제 #5
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, index=True, default=datetime.utcnow)
    content=db.Column(db.UnicodeText, nullable=False) 
    user_id=db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    category=db.Column(db.String(20), nullable=False)
    comment=db.relationship('Comment', backref='post_comments', lazy='dynamic', cascade='all, delete-orphan')
    tags=db.relationship('Tag', secondary=tags, backref=db.backref('posts', lazy='dynamic'), lazy='dynamic')
    reads=db.Column(db.Integer, default=0)
    
    nbcomments=db.Column(db.Integer, default=0)
    liked=db.relationship('PostLike', backref='post_liked', lazy='dynamic', cascade='all, delete-orphan')
    nbrlikes=db.Column(db.Integer, default=0, nullable=False)

    extend_existing=True

    @property
    def read(self):
        return self.reads

    @read.setter
    def read(self, r):
        self.reads=r
        
    @property
    def like(self):
        return self.nbrlikes

    @like.setter
    def like(self, r):
        self.nbrlikes=r        

    @like.setter
    def dislike(self, r):
        self.nbrlikes=r     

    @property
    def nbrcomments(self):
        return self.nbcomments

    @nbrcomments.setter
    def nbrcomments(self, c):
        self.nbcomments=c
       
    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
예제 #6
0
class PostLike(db.Model):
    id=db.Column(db.Integer, primary_key=True)
    user_id=db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    post_id=db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False)
예제 #7
0
class Cover(db.Model):
    id=db.Column(db.Integer, primary_key=True)
    data=db.Column(db.LargeBinary, nullable=False)
    file_id=db.Column(db.Integer, db.ForeignKey('file.id'), nullable=False)

    extend_existing=True
예제 #8
0
from flask_login import UserMixin, current_user, login_required
from myapp.factory import admin
from flask_admin.contrib.sqla import ModelView
from flask_admin import AdminIndexView, expose
from flask_admin.form import rules
from wtforms import widgets,TextAreaField, PasswordField
import json


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


notifs=db.Table('user_notifs',
    db.Column('user_id', db.Integer, db.ForeignKey('user.id'), nullable=True),
    db.Column('notif_id', db.Integer, db.ForeignKey('notif.id'), nullable=True)

)

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_file=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='dynamic', cascade='all, delete-orphan')
    location=db.Column(db.String(30), nullable=True)  #ici
    member_since=db.Column(db.DateTime(), default=datetime.utcnow)
    notifs=db.relationship('Notif', secondary=notifs, backref=db.backref('user', lazy='dynamic'), lazy='dynamic')
    nbrnotifs=db.Column(db.Integer, default=0)