def find_foods_worked_off(self, e): foods = Food.all() foods.filter("calories_left >", 0) res = [] calories = int(calc_exercisecalories(e.burnrate, e.duration)) for food in foods: res.append(food) if food.calories_left > calories: food.calories_left -= calories food.put() break else: calories -= food.calories food.calories_left = 0 food.put() return res