def edit_model(model_id): if request.method == "POST": name = request.form['name'] model = StoreModel.find_by_id(model_id) model.name = name try: model.save_to_db() except: flash('Error renaming model', 'danger') #return "Error renaming model" return redirect(url_for(".index")) # What happens if it's a GET request return render_template("models/edit_model.html", model=StoreModel.find_by_id(model_id))
def index(): model_id = request.args.get('model_id') model = StoreModel.find_by_id(model_id) #print(model) #print(store_list_schema.dump(model.items)) return render_template("items/index.html", items=item_list_schema.dump(model.items), model=model)
def post(self, name): if ItemModel.find_by_name(name): return {'message': "An item with name '{}' already exists.".format(name)}, 400 data = Item.parser.parse_args() item = ItemModel(name, **data) if StoreModel.find_by_id(item.store_id) is None: return {'message': "An Store with id '{}' does not exit.".format(item.store_id)}, 400 try: item.save_to_db() except: return {"message": "An error occurred inserting the item."}, 500 return item.json(), 201
def delete_model(model_id): model = StoreModel.find_by_id(model_id) if model.username == session["username"]: model.delete_from_db() return redirect(url_for(".index"))