Skip to content

Commit

Permalink
fixed post
Browse files Browse the repository at this point in the history
  • Loading branch information
el-agua committed Apr 25, 2024
1 parent 5e52103 commit 4dd214e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions backend/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,22 +847,23 @@ class CommentList(generics.ListAPIView):
def get(self, request, course_code, sort_by):
queryset = self.get_queryset()
l = queryset.count()
if sort_by == "newest":
returnset = queryset.order_by("likes", "path")
print(queryset)
if sort_by == "popular":
returnset = queryset.all().order_by("likes", "path")
elif sort_by == "oldest":
returnset = queryset.order_by("path")
elif sort_by == "popular":
returnset = queryset.all().order_by("path")
elif sort_by == "newest":
returnset = queryset.annotate(
path_sort = l - Cast(
Substr("path",
1,
StrIndex("path", Value("."))-1
), IntegerField()
)
).order_by("path_sort", "path")
return Response(returnset, status=status.HTTP_200_OK)
).all().order_by("path_sort", "path")
return Response(CommentSerializer(returnset, many=True).data, status=status.HTTP_200_OK)
def get_queryset(self):
return Comment.objects.filter(course__code=self.kwargs["course_code"])
return Comment.objects.filter(course__full_code=self.kwargs["course_code"])

# CommentViewSet
class CommentViewSet(viewsets.ModelViewSet):
Expand Down

0 comments on commit 4dd214e

Please sign in to comment.