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

Include attachment details in the article's detailed response #400

Merged
merged 1 commit into from
Jul 31, 2023
Merged
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
8 changes: 6 additions & 2 deletions apps/core/serializers/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.utils.translation import gettext
from rest_framework import exceptions, serializers
from rest_framework.utils.serializer_helpers import ReturnDict

from apps.core.documents import ArticleDocument
from apps.core.models import Article, ArticleHiddenReason, Block, Board, Comment, Scrap
Expand All @@ -11,6 +12,7 @@
HiddenSerializerFieldMixin,
HiddenSerializerMixin,
)
from apps.core.serializers.attachment import AttachmentSerializer
from apps.core.serializers.topic import TopicSerializer
from apps.user.serializers.user import PublicUserSerializer
from ara.classes.serializers import MetaDataModelSerializer
Expand Down Expand Up @@ -315,9 +317,11 @@ def get_side_articles_of_recent_article(self, obj, request):
after = None if len(after) == 0 else after[0]
return after, before

def get_attachments(self, obj) -> list | None:
def get_attachments(self, obj: Article) -> ReturnDict | None:
if self.visible_verdict(obj):
return obj.attachments.all().values_list("id")
attachments = obj.attachments.all()
serializer = AttachmentSerializer(attachments, many=True)
return serializer.data
return None

def get_my_comment_profile(self, obj):
Expand Down
Loading