Thursday, November 17, 2022

Random different values on each request

Hello friends,
I am trying to get 2 random values on each response using order_by('?')[:2], but getting the same response each time.  also tried RandomManager() as described here. , but still getting the same response.   (SQL query:  SELECT TOP 2 * FROM QuizBank ORDER BY NEWID())
class GetEssayQuestion(APIView):
    def get(self, request):
        data = Quizbank.objects.all().filter(status=1, section=5).order_by('?')[:2]
        serializer = QuizbankSerializer(data, many=True)
        return Response(

Appreciate any reference? Thanks.

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

No comments:

Post a Comment