diff --git a/flashcards/models.py b/flashcards/models.py index b2af835..b41bf9f 100644 --- a/flashcards/models.py +++ b/flashcards/models.py @@ -113,7 +113,7 @@ class Flashcard(Model): :param user: :return: A queryset with all cards that should be visible to a user. """ - return cls.objects.filter(hidden=False).exclude(userflashcard=user, userflashcard__pulled=None) + return cls.objects.filter(is_hidden=False).exclude(userflashcard__user=user, userflashcard__pulled=None) class UserFlashcardQuiz(Model): diff --git a/flashcards/views.py b/flashcards/views.py index 355f3d0..613ee6e 100644 --- a/flashcards/views.py +++ b/flashcards/views.py @@ -24,6 +24,17 @@ class SectionViewSet(ReadOnlyModelViewSet): pagination_class = StandardResultsSetPagination permission_classes = [IsAuthenticated] + @detail_route(methods=['get'], permission_classes=[IsAuthenticated]) + def flashcards(self, request, pk): + """ + Gets flashcards for a section, excluding hidden cards. + Returned in strictly chronological order (material date). + """ + flashcards = Flashcard.cards_visible_to(request.user).filter( \ + section=self.get_object(), is_hidden=False).all() + + return Response(FlashcardSerializer(flashcards, many=True)) + @detail_route(methods=['post'], permission_classes=[IsAuthenticated]) def enroll(self, request, pk): """