Random different values on each request

23 Aufrufe
Direkt zur ersten ungelesenen Nachricht

cs.s...@gmail.com

ungelesen,
17.11.2022, 09:21:5117.11.22
an Django users
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.

RANGA BHARATH JINKA

ungelesen,
19.11.2022, 04:19:4019.11.22
an django...@googlegroups.com
Hi,

You can use random module in python to generate random numbers 

Thanks and Regards

J. Ranga Bharath
Cell: 9110334114
   

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

subin

ungelesen,
19.11.2022, 12:30:5319.11.22
an django...@googlegroups.com
Please let me know if that sounds okay.

subin

ungelesen,
19.11.2022, 12:31:2519.11.22
an django...@googlegroups.com
Please reach out to Sophie at .

On Sat, Nov 19, 2022 at 10:19 AM RANGA BHARATH JINKA <bharath...@gmail.com> wrote:

subin

ungelesen,
19.11.2022, 12:32:2419.11.22
an django...@googlegroups.com
Thanks for reaching out! This inbox is not monitored. Please call this number or email us at

On Sat, Nov 19, 2022 at 10:19 AM RANGA BHARATH JINKA <bharath...@gmail.com> wrote:

subin

ungelesen,
19.11.2022, 12:33:0219.11.22
an django...@googlegroups.com
Please let me know if that is acceptable with you.

On Sat, Nov 19, 2022 at 10:19 AM RANGA BHARATH JINKA <bharath...@gmail.com> wrote:

subin

ungelesen,
19.11.2022, 16:05:3019.11.22
an django...@googlegroups.com
Thanks again for all your help.

--
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten