class PoliticalParty(db.Model): id = db.Column(db.Char(38), primary_key=True) Name = db.Column(db.Varchar(255), nullable=False) Votes = db.relationship('Vote', backref='party', lazy=True) def __repr__(self): return f"PoliticalParty('{self.Name}')"
class Grocery(db.Model): id = db.Column(db.Integer, primary_key=True) items = db.Column(db.String(300)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return '<Grocery {}>'.format(self.items)
class Listdb(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) list_name = db.Column(db.String(100)) file_name = db.Column(db.String(300)) def __repr__(self): return '<Listdb {}>'.format(self.list_name)
class Vote(db.Model): id = db.Column(db.Char(38), primary_key=True) User_id = db.Column(db.Char(38), db.ForeignKey('user.id'), nullable=False) Party_id = db.Column(db.Char(38), db.ForeignKey('party.id'), nullable=False) VoteStatus = db.Column(db.TINYINT(1)) def __repr__(self): return f"Vote('{self.VoteStatus}')"
class Users(db.Model): id = db.Column(db.Char(38), primary_key=True) EligibleToVote = db.Column(db.TINYINT(1)) Email = db.Column(db.Varchar(255), nullable=False) Password = db.Column(db.Varchar(255), nullable=False) IsOfficial = db.Column(db.TINYINT(1)) Votes = db.relationship('Vote', backref='user', lazy=True) def __repr__(self): return f"Users('{self.EligibleToVote}', '{self.Email}', '{self.Password}', '{self.IsOfficial}')"
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)) current_list = db.Column(db.String(100)) listdb = db.relationship('Listdb', backref='shopper', lazy='dynamic') about_me = db.Column(db.String(140)) last_seen = db.Column(db.DateTime, default=datetime.utcnow) age = db.Column(db.Integer) height = db.Column(db.Integer) weight = db.Column(db.Integer) gender = db.Column(db.String(1)) gym = db.Column(db.Integer) goals = db.Column(db.Integer) restrictions = db.Column(db.String(10)) cuisine = db.Column(db.String(200)) complexity = db.Column(db.Integer) daily_cal = db.Column(db.Integer) protein = db.Column(db.Integer) fat = db.Column(db.Integer) carb = db.Column(db.Integer) scores_fn = db.Column(db.String) def __repr__(self): return '<User {}>'.format(self.username) def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) def avatar(self, size): digest = md5(self.email.lower().encode('utf-8')).hexdigest() return 'https://gravatar.com/avatar/{}?d=retro&s={}'.format( digest, size) def nutrigen(self): self.daily_cal = nutrition.calc_cal(self.weight, self.height, self.age, self.gender, self.gym, self.goals) self.protein, self.fat, self.carb = nutrition.calc_macros( self.daily_cal, self.weight, self.goals) def list_initialize(self): self.scores_fn = nutrition.list_gen()