def _add_food(self): name = self.request.get('foodName') calories = calc_foodcalories(name) image = find_image(name) now = datetime.datetime.now().date() f = Food(name = name, calories = calories, calories_left = calories, imagelink = image, time = now) f.put() self.present_food(f)
def post(self): nameOfFood = self.request.get('food-name', allow_multiple=True) dateOfExpiration = self.request.get('expirationDate', allow_multiple=True) pickYourTitle = self.request.get('title') #fill list with key values listOfFoods = [] for i in range(len(nameOfFood)): food = Food(food=nameOfFood[i], expirationDate=datetime.strptime( dateOfExpiration[i], '%Y-%m-%d')) foodKey = food.put() listOfFoods.append(foodKey) #save to grocery list to database groceryToSave = Grocery(title=pickYourTitle, foods=listOfFoods) groceryToSave.put() self.redirect('/loadlist')