Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can we get all usernames list only not user objects with django ORM

I want to know that how can we get list of required field data from django models. In my case i want to get all usernames from users models.

receivers = User.objects.all()

this return all users objects. I want to get usernames directly. Something like below:

receivers = User.objects.all(username)
output:
["ahmed","dummy","hamza","sentence"]

in sql query looks like below:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT username from USER

>Solution :

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

Try this code, you can read more about this in django offical documents

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading