Reputation: 21
i'm trying to shuffle a list in django.views
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 ?
Upvotes: 1
Views: 2973
Reputation: 21
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
Upvotes: -2