def put(self, name): data = Item.parser.parse_args() item = ItemModel.getItem(name) if item is None: item = ItemModel(name, data['price'], data['store_id']) else: item.price = data['price'] item.store_id = data['store_id'] item.save_to_db() return item.json()
def put(self, name): data = Item.parser.parse_args() item = ItemModel.find_by_name(name) if not item: item = ItemModel(name, **data) else: item.price = data["price"] item.save_to_db() return item.json()
def put(self, name): payload = ItemController.parser.parse_args() item = ItemModel.find_by_name(name) if item is None: item = ItemModel(name, **payload) else: item.price = payload.get('price') item.save_to_db() return item.json()
def put(self, name): req = Item.parser.parse_args() i = ItemModel.get_item_by_name(name) if i is None: i = ItemModel(name, req['price']) else: i.price = req['price'] i.save_to_db() return i.json(), 201
def put(self, name): data_request = Item.parser.parse_args() item = ItemModel.find_by_name(name) # updated_item = ItemModel(name, data_request["price"]) if not item: item = ItemModel(name=name, **data_request) else: item.price = data_request["price"] item.save_to_db() return item.json()
def put(self, name): data = Item.parser.parse_args() item = ItemModel.find(name) if not item: item = ItemModel(name, **data) else: item.price = data["price"] item.store_id = data["store_id"] try: item.save() return item.json() except: return {"message": "An error occurred updating the item"}, 500