7주차 기본과제#70
Open
boxyhn wants to merge 11 commits into
Open
Conversation
BDlhj
requested changes
May 10, 2023
BDlhj
left a comment
There was a problem hiding this comment.
어려운 과제였음에도 불구하고 심화과제까지 마무리하느라 수고 많았어요👍🏻
| model = Post | ||
| fields = "__all__" No newline at end of file | ||
| fields = "__all__" | ||
| order = ['total_likes'] No newline at end of file |
Comment on lines
+34
to
+35
| # def count_likes(self, post): | ||
| # return post.like_user.filter(True).count() |
There was a problem hiding this comment.
아래에도 보이는데 필요가 없어서 주석 처리한 부분들은 삭제하고 push하는 게 좋습니다!
| # return post.like_user.filter(True).count() | ||
| ### 얘네가 class inner function 들! ### | ||
| def get(self, request): | ||
| posts = Post.objects.all() |
| ### 얘네가 class inner function 들! ### | ||
| def get(self, request): | ||
| posts = Post.objects.all() | ||
| posts = Post.objects.annotate(total_count= Count('like')).order_by("-total_count") |
|
|
||
| # Create your views here. | ||
|
|
||
| class CommentCreateView(APIView): |
There was a problem hiding this comment.
해당 class는 comment를 create만 하는 것이 아니기 때문에 아래에 있는 CommentDetailView와 대응되도록 CommentListView라고 naming하는 것이 더 좋아보입니다~~
Comment on lines
+14
to
+15
| author=request.user | ||
| post = request.data.get('post') |
There was a problem hiding this comment.
Suggested change
| author=request.user | |
| post = request.data.get('post') | |
| author = request.user | |
| post = request.data.get('post') |
사소한 부분이지만 지켜줘야합니다! 아래에도 조금씩 보이네요
| content=request.data.get('content') | ||
| if not author.is_authenticated: | ||
| return Response({"detail": "Authentication credentials not provided"}, status=status.HTTP_401_UNAUTHORIZED) | ||
| if not content: |
There was a problem hiding this comment.
지금은 content field가 비어있는지 여부만 체크하고 post field에 대해서는 체크하지 않네요! post field에 대해서도 체크해주어야 합니다!
Comment on lines
+37
to
+38
| if not post_id: | ||
| return Response({"detail": "missing fields ['post']"},status=status.HTTP_400_BAD_REQUEST) |
Comment on lines
+54
to
+56
| content=request.data.get('content') | ||
| if not content: | ||
| return Response({"detail": "missing fields ['content']"}, status=status.HTTP_400_BAD_REQUEST) |
There was a problem hiding this comment.
이 부분도 CommentSerializer를 거치기 전에 적어주는 게 맞을 것 같습니다! 순서를 한번 잘 생각해보세요!
| content=request.data.get('content') | ||
| if not content: | ||
| return Response({"detail": "missing fields ['content']"}, status=status.HTTP_400_BAD_REQUEST) | ||
| serializer.save() |
There was a problem hiding this comment.
혹시 is_valid()를 호출하지 않았는데 save()가 정상적으로 동작했나요??
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.