Skip to content

Commit

Permalink
Merge 5b80242 into bc5d2d7
Browse files Browse the repository at this point in the history
  • Loading branch information
oma0256 committed Mar 27, 2019
2 parents bc5d2d7 + 5b80242 commit 8523ddd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions authors/apps/articles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ArticleSerializer (serializers.ModelSerializer):
read_time = serializers.SerializerMethodField()
share_links = serializers.SerializerMethodField()
read_stats = serializers.SerializerMethodField()
has_reported = serializers.SerializerMethodField()

class Meta:
model = models.Article
Expand All @@ -46,6 +47,7 @@ class Meta:
"read_time",
"share_links",
'read_stats',
'has_reported'
)
read_only_fields = (
'author',
Expand Down Expand Up @@ -106,6 +108,14 @@ def get_read_stats(self, obj):
return None
return models.ReadStats.objects.filter(article=obj).count()

def get_has_reported(self, obj):
request = self.context.get('request')
if request.user.is_anonymous:
return False
reports = obj.report_set.all()
reporters = [report.reporter.username for report in reports]
return True if request.user.username in reporters else False


class ArticleRatingSerializer(serializers.ModelSerializer):
title = serializers.SerializerMethodField()
Expand Down

0 comments on commit 8523ddd

Please sign in to comment.