User.objects.all() only returns username

600 views
Skip to first unread message

Mohsen Pahlevanzadeh

unread,
Jul 3, 2020, 2:35:10 AM7/3/20
to Django users
When  I use select * from auth_user; I get the following result:
########################################################################
+----+--------------------------------------------------------------------------------+------------+--------------+----------+------------+-----------+--------------------------+----------+-----------+----------------------------+
| id | password                                                                       | last_login | is_superuser | username | first_name | last_name | email                    | is_staff | is_active | date_joined                |
+----+--------------------------------------------------------------------------------+------------+--------------+----------+------------+-----------+--------------------------+----------+-----------+----------------------------+
|  1 | pbkdf2_sha256$180000$8waw72qXD5IL$nDgySLTPAt3uLNnUMhzpPVodbkGYtYJJsmBilA7X6g8= | NULL       |            1 | mohsen   |            |           | moh...@pahlevanzadeh.net |        1 |         1 | 2020-07-03 05:57:34.351606 |
|  2 | pbkdf2_sha256$180000$NNVfAk9Z98Uz$5m6HPp42ytlZeyLiy8jsYgUKjREu8WbDeLhAb7dFi0M= | NULL       |            1 | ali      |            |           | a...@example.com            |        1 |         1 | 2020-07-03 05:58:09.429542 |
+----+--------------------------------------------------------------------------------+------------+--------------+----------+------------+-----------+--------------------------+----------+-----------+----------------------------+
2 rows in set (0.000 sec)

#########################################################################

And When I print(User.objects.all()) , I get the following result:
#########################################
<QuerySet [<User: mohsen>, <User: ali>]>
[03/Jul/2020 05:58:33] "GET /sql/ HTTP/1.1" 200 4
##########################################

Why I can't see all of my fields?

RANGA BHARATH JINKA

unread,
Jul 3, 2020, 2:40:17 AM7/3/20
to django...@googlegroups.com
send me your models.py 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/12b372dc-973d-482f-8888-0f79997bdadeo%40googlegroups.com.


--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114
Message has been deleted

RANGA BHARATH JINKA

unread,
Jul 3, 2020, 3:14:35 AM7/3/20
to django...@googlegroups.com
Send me views.py

On Fri, 3 Jul 2020, 12:36 pm Mohsen Pahlevanzadeh, <m.pahle...@gmail.com> wrote:
I don't have model.py for auth_user.
send me your models.py 

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.


--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Hella Nick

unread,
Jul 3, 2020, 3:15:43 AM7/3/20
to django...@googlegroups.com
send me your models.py and views.py


RANGA BHARATH JINKA <bharath...@gmail.com>于2020年7月3日 周五15:13写道:

Mohsen Pahlevanzadeh

unread,
Jul 3, 2020, 3:18:13 AM7/3/20
to Django users

By managed.py inspectdb auth_user :
$ ./manage.py inspectdb auth_user;

from django.db import models
class AuthUser(models.Model):
    password = models.CharField(max_length=128)
    last_login = models.DateTimeField(blank=True, null=True)
    is_superuser = models.IntegerField()
    username = models.CharField(unique=True, max_length=150)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=150)
    email = models.CharField(max_length=254)
    is_staff = models.IntegerField()
    is_active = models.IntegerField()
    date_joined = models.DateTimeField()
    class Meta:
        managed = False
        db_table = 'auth_user'

On Friday, July 3, 2020 at 11:10:17 AM UTC+4:30, RANGA BHARATH JINKA wrote:
send me your models.py 

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Jatin Agrawal

unread,
Jul 3, 2020, 3:18:40 AM7/3/20
to Django users
When we do, User.objects.all(), it returns a queryset which will show you all the objects that are present in the database for the model. So, when you print that queryset, it just displays the username of the user.

This is also because the def __str__ method of the User model must be returning the username. So, if you want to see all the fields of, check out this link: https://stackoverflow.com/questions/3106295/django-get-list-of-model-fields

Тарас Лисак

unread,
Jul 3, 2020, 11:09:38 AM7/3/20
to django...@googlegroups.com
Hello, 
you get this because in django by default implements __str__ method of User model, which returns only username of each user. If you want to have different behaviour, you should implement your one __str__ method in User model.

пт, 3 лип. 2020 о 09:35 Mohsen Pahlevanzadeh <m.pahle...@gmail.com> пише:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages