0

I'm trying to print some query with values_list but for some reason it is still printing and I need to be gone and only have the list inside the square brackets...

def resum(request):
    usuari=Usuari.objects.order_by('usuari_id').values_list('usuari_id', flat=True)
    print(usuari)

and what i get printed is:

<QuerySet [1, 2, 3, 4, 5, 6, 50, 51]>
[06/Jun/2019 01:21:04] "GET /resum/ HTTP/1.1" 200 2102

Any idea??

Thanks!

Billy Mango
  • 63
  • 1
  • 8
  • 2
    That's how it is supposed to work https://stackoverflow.com/questions/37205793/django-values-list-vs-values – HuLu ViCa Jun 05 '19 at 23:29

1 Answers1

2

Simply use the list() function:

def resum(request):
    usuari=Usuari.objects.order_by('usuari_id').values_list('usuari_id', flat=True)

    print(list(usuari))
Lord Elrond
  • 13,430
  • 7
  • 40
  • 80