def put(self, stude_id): data = Student.parser.parse_args() item = StudentModel.find_by_id(stude_id) if item is None: item = StudentModel(stude_id, **data) else: item.name = data['name'] item.course = data['course'] item.year = data['year'] item.gender = data['gender'] item.save_to_db() return item.json()
def post(self, stude_id): if StudentModel.find_by_id(stude_id): return { 'message': "Student ID '{}' already exist.".format(stude_id) }, 400 data = request.get_json() item = StudentModel(stude_id, **data) try: item.save_to_db() except: return {"message": "An error occured in inserting the item."}, 500 return item.json(), 201