def get_created_by(obj): from apps.user.serializers.user import PublicUserSerializer if obj.is_anonymous: return '익명' return PublicUserSerializer(obj.created_by).data
class CommentListActionSerializer(BaseCommentSerializer): from apps.user.serializers.user import PublicUserSerializer created_by = PublicUserSerializer(read_only=True, ) my_vote = serializers.SerializerMethodField(read_only=True, ) is_hidden = serializers.SerializerMethodField(read_only=True, ) why_hidden = serializers.SerializerMethodField(read_only=True, ) content = serializers.SerializerMethodField(read_only=True, ) hidden_content = serializers.SerializerMethodField(read_only=True, ) created_by = serializers.SerializerMethodField(read_only=True, )
class ReportSerializer(BaseReportSerializer): from apps.core.serializers.article import ArticleListActionSerializer parent_article = ArticleListActionSerializer(read_only=True, ) from apps.core.serializers.comment import CommentListActionSerializer parent_comment = CommentListActionSerializer(read_only=True, ) from apps.user.serializers.user import PublicUserSerializer reported_by = PublicUserSerializer(read_only=True, )
class CommentCreateActionSerializer(BaseCommentSerializer): class Meta(BaseCommentSerializer.Meta): read_only_fields = ( 'positive_vote_count', 'negative_vote_count', 'created_by', ) from apps.user.serializers.user import PublicUserSerializer created_by = PublicUserSerializer(read_only=True, )
def get_created_by(self, obj): from apps.user.serializers.user import PublicUserSerializer if obj.is_anonymous: return '익명' data = PublicUserSerializer(obj.created_by).data data['is_blocked'] = Block.is_blocked( blocked_by=self.context['request'].user, user=obj.created_by) return data
class CommentUpdateActionSerializer(BaseCommentSerializer): class Meta(BaseCommentSerializer.Meta): read_only_fields = ( 'is_anonymous', 'positive_vote_count', 'negative_vote_count', 'created_by', 'parent_article', 'parent_comment', ) from apps.user.serializers.user import PublicUserSerializer created_by = PublicUserSerializer(read_only=True, )
class CommentListActionSerializer(BaseCommentSerializer): from apps.user.serializers.user import PublicUserSerializer created_by = PublicUserSerializer(read_only=True, ) from apps.core.serializers.comment_log import CommentUpdateLogSerializer comment_update_logs = CommentUpdateLogSerializer( many=True, read_only=True, source='comment_update_log_set', ) my_vote = serializers.SerializerMethodField(read_only=True, ) my_report = serializers.SerializerMethodField(read_only=True, ) is_hidden = serializers.SerializerMethodField(read_only=True, ) why_hidden = serializers.SerializerMethodField(read_only=True, ) content = serializers.SerializerMethodField(read_only=True, ) hidden_content = serializers.SerializerMethodField(read_only=True, ) created_by = serializers.SerializerMethodField(read_only=True, )
class ScrapSerializer(BaseScrapSerializer): from apps.core.serializers.article import ArticleListActionSerializer parent_article = ArticleListActionSerializer(read_only=True, ) from apps.user.serializers.user import PublicUserSerializer scrapped_by = PublicUserSerializer(read_only=True, )
class BlockSerializer(BaseBlockSerializer): class Meta(BaseBlockSerializer.Meta): read_only_fields = ('blocked_by', ) from apps.user.serializers.user import PublicUserSerializer user = PublicUserSerializer(read_only=True, )