示例#1
0
class User(db.Model, UserMixin):
    #req
    user_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(25), unique=True, nullable=False)
    email = db.Column(db.String(128), unique=True, nullable=False)
    password = db.Column(db.String(128), nullable=False)
    tc_check = db.Column(db.Boolean, nullable=False)
    #times
    tl = db.Column(db.DateTime(), default=datetime.utcnow)
    last_login = db.Column(db.DateTime(),
                           default=datetime.utcnow,
                           onupdate=datetime.utcnow)
    #other
    visit_count = db.Column(db.Integer, default=0)
    about = db.Column(db.VARCHAR(),
                      default="Welcome to my Profile and Fileshare!")
    posted_count = db.Column(db.Integer, default=0)
    total_downloads = db.Column(db.Integer, default=0)
    #photo
    user_photo = db.Column(db.String(255))
    priv_key = db.Column(db.Text())

    posted = db.relationship('Post', backref='author', lazy=True)

    def __repr__(self):
        return f"User('{self.user_id}','{self.username}','{self.email}','{self.last_login}','{self.created}')"
##UserMixin
##requires a method that can uniquely identify a user

    def get_id(self):
        return (self.user_id)
示例#2
0
class Post(db.Model):
    __tablename__='posts'
    id = db.Column(db.Integer, primary_key=True)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    content = db.Column(db.Text(240), nullable=False)

    def __repr__(self):
        return 'Post(%s,%s)' %(self.content,self.date_posted)
class Post(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(240), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return 'Post(%s,%s)' % (self.content, self.date_posted)
示例#4
0
class User(db.Model,UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name=db.Column(db.String(60),nullable=False,unique=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email=db.Column(db.String(140),nullable=False,unique=True)
    password = db.Column(db.String(60), nullable=False)
    location=db.Column(db.String(64))
    about_me=db.Column(db.Text())

    def __repr__(self):
        return 'User(%s,%s,%s)' %(self.name,self.email,self.password)
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), nullable=False, unique=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(140), nullable=False, unique=True)
    password = db.Column(db.String(60), nullable=False)
    location = db.Column(db.String(64))
    about_me = db.Column(db.Text())
    date_joined = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    post = db.relationship('Post', backref='author', lazy=True)

    def __repr__(self):
        return 'User(%s,%s,%s)' % (self.name, self.email, self.password)