Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comment AllowAny & comment author_username / author_info #115

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sharkle/article/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import serializers
from article.models import Article
from user.serializers import UserViewSerializer


class ArticleCreateSerializer(serializers.ModelSerializer):
Expand All @@ -15,6 +16,7 @@ class Meta:
class ArticleSerializer(serializers.ModelSerializer):
author_id = serializers.SerializerMethodField()
author_username = serializers.SerializerMethodField()
author_info = serializers.SerializerMethodField()
comments_counts = serializers.SerializerMethodField()

class Meta:
Expand All @@ -23,6 +25,7 @@ class Meta:
"id",
"author_id",
"author_username",
"author_info",
"is_private",
"title",
"content",
Expand All @@ -38,6 +41,9 @@ def get_author_id(self, obj):
def get_author_username(self, obj):
return obj.author.username

def get_author_info(self, obj):
return UserViewSerializer(obj.author).data

def get_comments_counts(self, obj):
print(type(obj.comments))
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기 print문이..!

return obj.comments.count()
15 changes: 15 additions & 0 deletions sharkle/comment/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from rest_framework import serializers
from comment.models import Comment
from user.serializers import UserViewSerializer


class CommentCreateSerializer(serializers.ModelSerializer):

class Meta:
model = Comment
fields = "__all__"
Expand All @@ -13,6 +15,19 @@ class Meta:


class CommentSerializer(serializers.ModelSerializer):
author_id = serializers.SerializerMethodField()
author_username = serializers.SerializerMethodField()
author_info = serializers.SerializerMethodField()

class Meta:
model = Comment
fields = "__all__"

def get_author_id(self, obj):
return obj.author.id

def get_author_username(self, obj):
return obj.author.username

def get_author_info(self, obj):
return UserViewSerializer(obj.author).data
3 changes: 2 additions & 1 deletion sharkle/comment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
class CommentViewSet(viewsets.GenericViewSet):
queryset = Comment.objects.all()
serializer_class = CommentSerializer
permission_classes = (permissions.IsAuthenticated,) # TODO
#permission_classes = (permissions.IsAuthenticated,)
permission_classes = (permissions.AllowAny,) # TODO

def dfs_comment(self, article_id):
comments = self.get_queryset().filter(article=article_id)
Expand Down
2 changes: 1 addition & 1 deletion sharkle/user_circle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def get_recruitment_alarm(cls, circle, user):
def get_alarm_dict(cls, circle, user):
data = dict()
data["alarm"] = user_status(circle, user)["alarm"]
data["live_recruitment_alarm"] = cls.get_recruitment_alarm(circle, user)
if data["alarm"]:
data["live_recruitment_alarm"] = cls.get_recruitment_alarm(circle, user)
board_alarm = cls.get_board_alarm_list(circle, user)
data["board_alarm"] = board_alarm
data["board_alarm_count"] = len(board_alarm)
Expand Down