Ejemplo n.º 1
0
def generate_meals(num_days: int):
    # increment by 1 day
    for i in range(0, num_days):
        meal_day = date.today() + timedelta(days=i)
        quantity = randint(1, 4)
        recipies = Recipe.objects
        random_recipe = recipies[randint(0, len(recipies))]
        print(random_recipe.title)

        meal = Meal(date=meal_day,
                    quantity=quantity,
                    note="randomly generated",
                    recipe_id=random_recipe.migros_id,
                    recipe_title=random_recipe.title)

        meal.save()
Ejemplo n.º 2
0
def create():
    data = request.json

    name = data.get('name')
    ingredients = data.get('ingredients')
    prep_time = data.get('prep_time')
    cookware = data.get('cookware')

    if name and ingredients and prep_time:
        meal = Meal(name=name,
                    ingredients=ingredients,
                    prep_time=prep_time,
                    cookware=cookware)
        if meal.save():
            return jsonify({
                "message": "Successfully created the meal!",
                "status": "success",
                "meal": {
                    "id": meal.id,
                    "name": meal.name
                }
            })
        elif meal.errors != 0:
            return jsonify({
                "message": [error for error in meal.errors],
                "status": "failed"
            })
    else:
        return jsonify({
            "message": "All fields are required!",
            "status": "failed"
        })
Ejemplo n.º 3
0
def create():

    resp = request.get_json()
    meal = resp.get('meal')
    food = resp.get('food')
    calories = resp.get('calories')

    meal = Meal(meal=meal, food=food, calories=calories)

    if meal.save():
        message = {'status': True, 'message': 'created'}
    else:
        message = {'status': False, 'message': user.errors}

    return jsonify(message)