Closed rollue closed 3 years ago
This was the best I can do - just in case someone needs this.
class CommentCreate(base_views.CommentCreate):
...
def post(self, request, *args, **kwargs):
resp = super().post(request, *args, **kwargs)
if self.resp_dict['code'] == 201: # The comment has been created.
resp.data["id"] = self.resp_dict["comment"]["xtd_comment"].id
return resp
Hi @mhoonjeon. Indeed, when the response code is 201, it should return the id of the new created message.
The fix for this issue has been released with v2.8.2.
Currently the comment id is missing from the comment create API response. When a user leaves a comment, he/she might want to delete the comment immediately. Unless we get the id in response to create(POST) request, this means we have to refresh the page to fetch the comment list on another request.
I have looked at the code to customize this behavior, but currently, it seems difficult to override the view or the serializer to achieve this. The best try is to use the self.resp_dict that contains XtdComment instance in CommentCreate API view, but I still have to rewrite the post method - it doesn't look pretty to me.
Any suggestions? I think it's worth making this field as default.