Skip to content

Commit

Permalink
Merge 7ff24f0 into 46884a8
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipotieno committed Jun 25, 2019
2 parents 46884a8 + 7ff24f0 commit 7e9bd1a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
21 changes: 13 additions & 8 deletions authors/apps/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def readtime(self):
timer = ArticleTimer(self)
return timer.get_read_time()


class Comment(models.Model):
"""
model for comments
Expand Down Expand Up @@ -281,17 +281,22 @@ def get_articles_details(self):
"updated_at": self.article.updated_at
}

def ratings(self, article, user):
def ratings(self, article_id, user):
"""
Model to display rating for users in an articles
"""

queryset = RatingModel.objects.filter(
article_id=article).first()
if queryset:
queryset1 = RatingModel.objects.filter(
article_id=article_id, rated_by_id=user).first()
queryset2 = RatingModel.objects.filter(
article_id=article_id).first()
if queryset1:
return {
"my_ratings": queryset1.rate,
"average_ratings": Article().average_ratings(article_id)
}
elif queryset2:
return {
"my_ratings": queryset.rate,
"average_ratings": Article().average_ratings(article)
"average_ratings": Article().average_ratings(article_id)
}
return 0

Expand Down
3 changes: 1 addition & 2 deletions authors/apps/articles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ def get_favorites(self, obj):
return mapped_data

def get_ratings(self, obj):
article = self.get_likes_data()
request = self.context.get('request', None)
ratings = RatingModel().ratings(article.id, request.user.id)
ratings = RatingModel().ratings(obj.id, request.user.id)
return ratings

def get_bookmarked(self, instance):
Expand Down
2 changes: 1 addition & 1 deletion authors/apps/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get(self, request):
'like_info',
'comments',
'favorites',
'ratings'
# 'ratings'
]
)
response = paginator.get_paginated_response({
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e9bd1a

Please sign in to comment.