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.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/800a6bc3-9870-47dd-8f41-54f13de108bdn%40googlegroups.com.