How can I retrieve a list of field for all objects in Django?

Have you tried

list(User.objects.all().values_list('username', flat=True)) 

If you only pass in a single field, you can also pass in the flat parameter. If True, this will mean the returned results are single values, rather than one-tuples. Additionally, casting it to a list makes the returned value a list instead of a queryset

Leave a Comment