class Product(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), index=True) price = db.Column(db.Float) img_src = db.Column(db.String(120)) category = db.Column(db.String(30), index=True) rewe_plz = db.Column(db.Integer, db.ForeignKey('rewe.plz')) on_sale = db.Column(db.Boolean, index=True, default=False)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key = True) first_name = db.Column(db.String(64), nullable = False) last_name = db.Column(db.String(64), nullable = False) email = db.Column(db.String(64), unique = True, nullable = False) password = db.Column(db.String(60), nullable = False) # flaskApi bcrypt (60 length) image_file = db.Column(db.String(20), nullable = False, default = 'default.jpg') role = db.Column(db.String(32), nullable = False, default = 'pending') date_created = db.Column(db.DateTime, nullable = False, default = datetime.utcnow) # Setting up a timed reset password token with app['SECRET_KEY'] and expiration time def get_reset_password_token(self, expire_sec = 300): s = Serializer(app.config['SECRET_KEY'], expire_sec) # Returning the token with the payload of (User) 'id' return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_password_reset_token(token): s = Serializer(app.config['SECRET_KEY']) # Token could be invalid/timed out, causing an exception try: user_id = s.loads(token)['user_id'] return User.query.get(user_id) except: return None # Object's repr print for debuging def __repr__(self): return f"User('{self.id}', '{self.first_name}', '{self.last_name}', '{self.email}', {self.role}', '{self.date_created}')"
class User(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=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) isDisabled = db.Column(db.Boolean, nullable=False, default=False) isAdmin = db.Column(db.Boolean, nullable=False, default=False) created_date = db.Column(db.Date) last_login_time = db.Column(db.Date) threads = db.relationship('ConversationThread', backref='creator', lazy=True) rating = db.Column(db.Integer, default=0) threadsCreated = db.Column(db.Integer, default=0) threadsReplied = db.Column(db.Integer, default=0) def __repr__(self): return f"{self.id}, {self.username}, {self.email}, {self.image_file}, {self.password}, {self.isDisabled}, {self.created_date}, {self.last_login_time}"
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) plz = db.Column(db.Integer, db.ForeignKey('zipcode.id')) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) created_at = db.Column(db.DateTime, index=True, default=datetime.utcnow) last_login_at = db.Column(db.DateTime) is_admin = db.Column(db.Boolean, default=False) def user_to_json(self): return { "id": self.id, "name": self.username, "email": self.email, "plz": self.plz, "password_hash": self.password_hash, "created_at": self.created_at } def __repr__(self): return '<User {}>'.format(self.username)
class Message(db.Model): """docstring for Message.""" id = db.Column(db.Integer, primary_key=True) body = db.Column(db.String(64)) def to_dict(self): data = {'id': self.id, 'body': self.body} return data def from_dict(self, data): for field in "body": if field in data: setattr(self, field, data[field]) def __repr__(self): return '<{} : {}>'.format(self.body, self.body)
class Task(db.Model): """docstring for Task.""" id = db.Column(db.Integer, primary_key=True) longDescription = db.Column(db.String(64)) def to_dict(self): data = {'id': self.id, 'longDescription': self.longDescription} return data def from_dict(self, data): for field in "longDescription": if field in data: setattr(self, field, data[field]) def __repr__(self): return '<{} : {}>'.format(self.body, self.longDescription)
class Rewe(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), index=True) adress = db.Column(db.String(100), index=True, unique=True) plz = db.Column(db.Integer, db.ForeignKey('zipcode.id'))
class Zipcode(db.Model): id = db.Column(db.Integer, primary_key=True) district = db.Column(db.String(50), primary_key=True)