class User(db.Model, UserMixin): #we inherit from db.Model class and Usermixing class __tablename__ = 'users' #giving it a table name parameter, note, every user takes a row on the table, and each attribute take a column id = db.Column( db.Integer, primary_key=True ) #every user should have a unique primary key so we dont have overlapping primary keys email = db.Column( db.String(64), unique=True, index=True ) #the number 64 takes care of spam, unique takes care of more than one emails from users username = db.Column(db.String(64), unique=True, index=True) password_hash = db.Column(db.String( 128)) #we have 128 because the password hash can be very lenghty #we use this to create an instance of the User object def __init__(self, email, username, password): self.email = email #save the email self.username = username #save the username self.password_hash = generate_password_hash( password ) #we dont wantb to save the string the user typed in, we want to save the hashed password #in order to check when a user is login in, we need a method called check password def check_password(self, password): return check_password_hash( self.password_hash, password ) #this will accept password, hash it and check it against the selfpassword saved earlier
class Todo_Todo(db.Model): __tablename__ = "todos2" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(20)) todo_description = db.Column(db.String(100)) def __repr__(self): return f"{self.id}"
class dataLogin(db.Model, UserMixin): __tablename__ = "data_login" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(40)) email = db.Column(db.String(120)) password = db.Column(db.String(150)) def __repr__(self): return f"{self.id}"
class Todo(db.Model): __tablename__ = "todos" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(20)) todo_description = db.Column(db.String(100)) def create(self): db.session.add(self) db.session.commit() return self def __init__(self, title, todo_description): self.title = title self.todo_description = todo_description def __repr__(self): return f"{self.id}"
class dataMahasiswa(db.Model): __tablename__ = "data_mahasiswa_baru" id = db.Column(db.Integer, primary_key=True) nama = db.Column(db.String(50)) alamat = db.Column(db.String(80)) nim = db.Column(db.String(20), unique=True) def create(self): db.session.add(self) db.session.commit() return self def __init__(self, nama, alamat, nim): self.nama = nama self.alamat = alamat self.nim = nim def __repr__(self): return f"{self.id}"
class dataTest2(db.Model): __tablename__ = "data_test2" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(40)) datetime = db.Column(db.DateTime(6)) def create(self): db.session.add(self) db.session.commit() return self def __init__(self, nama, alamat, nim): self.nama = nama self.alamat = alamat self.nim = nim def __repr__(self): return f"{self.id}"