Esempio n. 1
0
class User(db.Model,UserMixin):
    id = db.Column(db.Integer, primary_key = True)
    username = db.Column(db.String(150), nullable = False)
    email = db.Column(db.String(150), unique = True, nullable = False)
    password = db.Column(db.String(256), nullable = False)
    post = db.relationship('Post', backref = 'author', lazy = True)
    
    def __init__(self,username,email,password):
        self.username = username
        self.email = email
        self.password = self.set_password(password)

    def __repr__(self):
        return '{} has been created'.format(self.username)

    def set_password(self,password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash
Esempio n. 2
0
class User(db.Model,UserMixin):
    id = db.Column(db.Integer, primary_key = True) # main identifier for our user table
    username = db.Column(db.String(150), nullable = False) # Telling our database that this CANNOT be empty when we say nullable = False
    email = db.Column(db.String(150), unique = True, nullable = False) # Telling our database that this has to be different each time when we say unique = True and that this cannot be empty either
    password = db.Column(db.String(256), nullable = False) # Telling our database that this CANNOT be empty when we say nullable = False
    post = db.relationship('Post', backref = 'author', lazy = True) # Connects which user actually creates the specific post

    def __init__(self,username,email,password):
        self.username = username
        self.email = email
        self.password = self.set_password(password) 

    def __repr__(self): 
        return '{} has been created'.format(self.username) # Lets us see what is being created  

    def set_password(self,password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash