Skip to content

7주차 기본과제#70

Open
boxyhn wants to merge 11 commits into
snulion11th-seminar:shihyunfrom
boxyhn:shihyun
Open

7주차 기본과제#70
boxyhn wants to merge 11 commits into
snulion11th-seminar:shihyunfrom
boxyhn:shihyun

Conversation

@boxyhn

@boxyhn boxyhn commented May 5, 2023

Copy link
Copy Markdown

No description provided.

@BDlhj BDlhj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어려운 과제였음에도 불구하고 심화과제까지 마무리하느라 수고 많았어요👍🏻

Comment thread post/serializers.py
model = Post
fields = "__all__" No newline at end of file
fields = "__all__"
order = ['total_likes'] No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 이 부분은 무엇을 위한 걸까요??

Comment thread post/views.py
Comment on lines +34 to +35
# def count_likes(self, post):
# return post.like_user.filter(True).count()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래에도 보이는데 필요가 없어서 주석 처리한 부분들은 삭제하고 push하는 게 좋습니다!

Comment thread post/views.py Outdated
# return post.like_user.filter(True).count()
### 얘네가 class inner function 들! ###
def get(self, request):
posts = Post.objects.all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 굳이 필요가 없겠죠?!

Comment thread post/views.py Outdated
### 얘네가 class inner function 들! ###
def get(self, request):
posts = Post.objects.all()
posts = Post.objects.annotate(total_count= Count('like')).order_by("-total_count")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotate와 order_by를 혼합하여 잘 사용해주었습니다👏🏻👏🏻

Comment thread comment/views.py

# Create your views here.

class CommentCreateView(APIView):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 class는 comment를 create만 하는 것이 아니기 때문에 아래에 있는 CommentDetailView와 대응되도록 CommentListView라고 naming하는 것이 더 좋아보입니다~~

Comment thread comment/views.py Outdated
Comment on lines +14 to +15
author=request.user
post = request.data.get('post')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
author=request.user
post = request.data.get('post')
author = request.user
post = request.data.get('post')

사소한 부분이지만 지켜줘야합니다! 아래에도 조금씩 보이네요

Comment thread comment/views.py Outdated
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금은 content field가 비어있는지 여부만 체크하고 post field에 대해서는 체크하지 않네요! post field에 대해서도 체크해주어야 합니다!

Comment thread comment/views.py
Comment on lines +37 to +38
if not post_id:
return Response({"detail": "missing fields ['post']"},status=status.HTTP_400_BAD_REQUEST)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-except보다 앞에서 이걸 확인해주면 어떨까요??

Comment thread comment/views.py
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 CommentSerializer를 거치기 전에 적어주는 게 맞을 것 같습니다! 순서를 한번 잘 생각해보세요!

Comment thread comment/views.py
content=request.data.get('content')
if not content:
return Response({"detail": "missing fields ['content']"}, status=status.HTTP_400_BAD_REQUEST)
serializer.save()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 is_valid()를 호출하지 않았는데 save()가 정상적으로 동작했나요??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants