def post(self): data = json.loads(request.data) user = g.user recipe = Recipe() recipe.name = data["name"] for ingredient in data["ingredients"]: irec = RecipeIngredient() irec.name = ingredient recipe.ingredients.append(irec) recipe.instructions = data["instructions"] recipe.author = data["author"] user.recipes.append(recipe) #db.session.add(recipe) try: db.session.commit() except Exception,e: print "error adding new record" db.session.rollback()