def add_plan(): errors = [] if request.is_json: data = request.get_json() print(data) plan = Plans(date=data.get('date'), meal_id=data.get('meal')) db.session.add(plan) db.session.commit() return str(plan.id), 200
"MA", "02138", "USA", "*****@*****.**", "9518162589", "it's a secret", "VENDOR", "cus_4fdAW5ftNQow1a")) db.session.add(Users( "javi", "fakes address", "Ranchoi", "CA", "91739", "USA", "*****@*****.**", "9518162555", "password", "CUSTOMER", "cus_4fdAW5ftNQow1a")) ''' db.session.add( Plans("plan_DSJ2J4GWgA6gV7", 1500, "Standard monthly vendor subscription")) db.session.add( Plans("plan_DSJ5PYWe9JZnuh", 3200, "Gold monthly vendor subscription")) #commit db.session.commit()
def add_meal(): message = [] results = {} if request.method == "POST": try: title = request.form['title'] ingredients = request.form['ingredients'] instructions = request.form['instructions'] image = request.form['image'] url = request.form['url'] date = request.form['plan_date'] if date: datum = datetime.strptime(date, "%Y-%M-%d").strftime("%Y-%M-%d") else: datum = '' results = { 'title': title, 'ingredients': ingredients, 'instructions': instructions, 'image': image, 'url': url, 'date': datum } try: meal = Meals(title=title, ingredients=ingredients, instructions=instructions, image=image, url=url, date_added=datetime.utcnow()) db.session.add(meal) db.session.flush() if date: plan = Plans(date=date, meal_id=meal.id) db.session.add(plan) db.session.commit() message.append({ 'title': "Successfully added {}".format(title), 'state': "success" }) except Exception as err: message.append({ 'title': 'Could not update database.', 'message': '{}'.format(err), 'state': 'error' }) except Exception as err: message.append({ 'title': "Error with form.", 'message': "{}".format(err), 'state': 'error' }) return render_template('add-meal.html', page_title="Mealer | Add Meal", message=message, values=results)