class Message(db.Model): id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime, index=True, default=datetime.utcnow) fname = db.Column(db.String(120)) lname = db.Column(db.String(120)) email = db.Column(db.String(120)) message = db.Column(db.Text)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(32), unique=True) password_hash = db.Column(db.String(128)) def __init__(self, username): self.username = username def set_password(self, password): self.password_hash = generate_password_hash(password) def validate_password(self, password): return check_password_hash(self.password_hash, password) def is_active(self): return True def get_id(self): return self.id def is_anonymous(self): return False def is_authenticated(self): return True
class User(BaseModel): __tablename__ = 'users' password = db.Column(db.String(), nullable=False) email = db.Column(db.String(), nullable=False) email_verified = db.Column(db.Boolean(), default=False) @classmethod def find_by_email(cls, email): return User.query.filter(User.email == email).first()
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) def check_password(self, password): return check_password_hash(self.password_hash, password) def __repr__(self): return f"<User {self.username}>"
class Task(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) uid = db.Column(db.Integer, db.ForeignKey(User.id)) task = db.Column(db.String(50)) description = db.Column(db.String(500)) done = db.Column(db.Boolean, default=False) timeStart = db.Column(db.DateTime, index=True) timeOver = db.Column(db.DateTime) def __init__(self, task, timeOver, uid): self.task = task self.timeStart = str(datetime.now())[0:19] self.timeOver = timeOver self.uid = uid
class Worker(db.Model): """Worker model.""" __tablename__ = "worker" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) surname = db.Column(db.String, nullable=False) email = db.Column(db.String, unique=True, nullable=False) phone = db.Column(db.String(13), unique=True, nullable=False) bdate = db.Column(db.DateTime, nullable=False) # birth date edate = db.Column(db.DateTime) # employment date idd = db.Column(db.Integer, db.ForeignKey('department.id')) # id of dep idp = db.Column(db.Integer, db.ForeignKey('position.id')) # id of position ishead = db.Column(db.Boolean, default=False) # is this head of depatment? def __init__(self, name, surname, email, phone, bdate, edate, idd, idp, ishead): """initialization.""" self.name = name self.surname = surname self.email = email self.phone = phone self.bdate = bdate self.edate = edate self.idd = idd self.idp = idp self.ishead = ishead
class User(Base): last_name = db.Column( db.String(128), nullable=False, ) first_name = db.Column(db.String(128), nullable=False) email = db.Column(db.String(128), nullable=False, unique=True) password = db.Column(db.String(192), nullable=False) def generate_reset_token(self): return URLSafeTimedSerializer(app.config['SECRET_KEY'], 'reset_token').dumps(self.email) @classmethod def retrive_reset_email(cls, token): return URLSafeTimedSerializer(app.config['SECRET_KEY'], 'reset_token').loads(token, max_age=86400)
class BaseModel(db.Model): __abstract__ = True id = db.Column(db.String(), primary_key=True) created_at = db.Column(db.DateTime, default=datetime.utcnow()) created_by = db.Column(db.String()) updated_at = db.Column(db.DateTime) updated_by = db.Column(db.String()) def __init__(self, **kwargs): super(BaseModel, self).__init__(**kwargs) self.id = str(uuid.uuid4()) def save(self): db.session.add(self) db.session.commit() @classmethod def commit(cls): db.session.commit()
class Department(db.Model): """Department model.""" __tablename__ = "department" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), unique=True, nullable=False) description = db.Column(db.Text, nullable=False) def __init__(self, name, description): """initialization.""" self.name = name self.description = description
class User(db.Model, UserMixin): __tablename__ = "users" __table_args__ = {"useexisting": True, 'mysql_collate': 'utf8_general_ci'} id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(100), unique=True, nullable=False) username = db.Column(db.String(100), nullable=False) _password = db.Column(db.String(512), nullable=False) def verify_password(self, _password): return self._password == _password # @hybrid_property # def password(self): # return self._password # @password.setter # def _set_password(self, plaintext): # self._password = bcrypt.generate_password_hash(plaintext) # def is_correct_password(self, plaintext): # return bcrypt.check_password_hash(self._password, plaintext) def __repr__(self): return "<User %r>" % self.username