Esempio n. 1
0
class User(db.Model, UserMixin):
    user_id = db.Column(db.Integer, primary_key=True)
    user_name = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    profile_pic = db.Column(db.String(20),
                            nullable=False,
                            default='default.jpg')
    password = db.Column(db.String(60), nullable=False)

    # get user_id
    def get_id(self):
        return (self.user_id)

    # generate random token which expires in 30 mins
    def get_reset_token(self, expires_sec=1800):
        s = Serializer(Config.SECRET_KEY, expires_sec)
        return s.dumps({'user_id': self.user_id}).decode('utf-8')

    # method to verify the user's reset token
    @staticmethod
    def verify_reset_token(token):
        s = Serializer(Config.SECRET_KEY)
        try:
            user_id = s.loads(token)['user_id']
        except Exception:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.user_name}', '{self.email}', '{self.profile_pic}')"
Esempio n. 2
0
class FoodOnMenu(db.Model):
    # compound primary keys
    food_id = db.Column(db.Integer,
                        db.ForeignKey('menu.menu_id'),
                        primary_key=True,
                        nullable=False)
    menu_id = db.Column(db.Integer,
                        db.ForeignKey('food.food_id'),
                        primary_key=True,
                        nullable=False)
Esempio n. 3
0
class Rating(db.Model):
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.user_id'),
                        primary_key=True,
                        nullable=False)
    food_id = db.Column(db.Integer,
                        db.ForeignKey('food.food_id'),
                        primary_key=True,
                        nullable=False)
    stars = db.Column(db.Integer, nullable=False)
    description = db.Column(db.String(300), nullable=True)
    timestamp = db.Column(db.DateTime, nullable=True)
Esempio n. 4
0
class Menu(db.Model):
    menu_id = db.Column(db.Integer, primary_key=True)
    meal_type = db.Column(db.Enum('breakfast', 'lunch', 'dinner'),
                          nullable=False)
    location = db.Column(db.Enum('Stwest', 'Steast', 'IV'), nullable=True)
    menu_date = db.Column(db.DateTime, nullable=True)
Esempio n. 5
0
class Food(db.Model):
    food_id = db.Column(db.Integer, primary_key=True)
    food_name = db.Column(db.String(100), nullable=True)
    serving = db.Column(db.Integer, nullable=True)
    calories = db.Column(db.Integer, nullable=True)
    calories_from_fat = db.Column(db.Integer, nullable=True)
    cholesterol = db.Column(db.Integer, nullable=True)
    dietary_fiber = db.Column(db.Integer, nullable=True)
    protein = db.Column(db.Integer, nullable=True)
    saturated_fat = db.Column(db.Integer, nullable=True)
    sodium = db.Column(db.Integer, nullable=True)
    sugar = db.Column(db.Integer, nullable=True)
    total_carbs = db.Column(db.Integer, nullable=True)
    total_fat = db.Column(db.Integer, nullable=True)
    trans_fat = db.Column(db.Integer, nullable=True)
    vitamin_d = db.Column(db.Integer, nullable=True)
    vegetarian = db.Column(db.Boolean, nullable=False)
    vegan = db.Column(db.Boolean, nullable=False)
    balanced = db.Column(db.Boolean, nullable=False)