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.
https://stackoverflow.com/questions/962619/how-to-pull-a-random-record-using-djangos-orm , but still getting the same response. (SQL query: SELECT TOP 2 * FROM QuizBank ORDER BY NEWID())
views.py:
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(serializer.data)
Appreciate any reference? Thanks.