def post(self, product_name): db.create_all() db.session.commit() if ProductsModel.find_by_name(product_name): return {'message': "An Record with name '{}' already exists.".format(product_name)}, 400 data = self.parser.parse_args() product = ProductsModel(product_name,**data,) product.created_by = 1 product.created_on = datetime.now() product.modified_by = 0 product.deleted_by = 0 try: product.save_to_db() except Exception as e: return {"message": "An error occurred while inserting the Record.'{}'".format(e)} return product.json(), 201
def post(self): data = self.parser.parse_args() product = ProductsModel(**data) product.created_by = 1 product.created_on = datetime.now() product.modified_by = 0 product.deleted_by = 0 product.modified_on = None product.deleted_on = None try: validateObj = ProductsModel.validateData(data, request) if type(validateObj) is dict: return {"success": False, "errors": validateObj}, 400 if ProductsModel.find_by_name(data['product_name']): return { "success": False, "message": "A product with that Record Name already exists" }, 400 name = data['product_name'] if name.strip(): product.save_to_db() product.token = encodeID(product.product_id) product.save_to_db() else: return { "success": False, "message": "String Should not be empty" } except Exception as e: return { "message": "An error occurred creating the Record.'{}'".format(e) }, 500 return product.json(), 201