def post(cls): name = request.get_json()["name"] if ListModel.find_by_name(name): return {"message": NAME_ALREADY_EXISTS.format(name=name)}, 400 list = ListModel(name=name) try: list.save_to_db() except: return {"message": ERROR_INSERTING}, 500 return list_schema.dump(list), 201
def post(self): try: user = user_schema.load(request.get_json()) except ValidationError as err: return err.messages, 400 if UserModel.find_by_username(user.username): return {"message": "A user with that username already exists"}, 400 user.save_to_db() thelist = ListModel("Gelen Kutusu") thelist.save_to_db() permission = ListPermissionModel(user.id, thelist.id) permission.save_to_db() #return {"message": "User created successfully."}, 201 return perm_schema.dump(permission)