def post(self):
"""
Create a model with data given in the request body. JSON format is
expected. The model performs the validation automatically when
instantiated.
"""
try:
data = request.json
self.check_create_permissions(data)
instance = self.model(**data)
instance.save()
return instance.serialize(), 201
except TypeError as exception:
current_app.logger.error(str(exception))
return {"error": str(exception)}, 400
except IntegrityError as exception:
current_app.logger.error(str(exception))
return {"error": str(exception)}, 400
except StatementError as exception:
current_app.logger.error(str(exception))
return {"error": str(exception)}, 400
except permissions.PermissionDenied:
abort(403)
评论列表
文章目录