'how to shuffle list in django views.py?
i'm trying to shuffle a list in django.views
views.py
import random
def all_songs( request):
songs_list = Songs.objects.all()
songs_list=random.shuffle(songs_list)
but after entering this code the error showing "'QuerySet' object does not support item assignment" shows up. how do i do it without item assignment ?
Solution 1:[1]
Solution 2:[2]
convert list(here song_list) to list and then shuffle it....
def all_songs( request):
songs_list = list(Songs.objects.all())
random.shuffle(songs_list)
no more queryset error
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sax |
| Solution 2 | Art |
