简体   繁体   English

获取特定用户的last_login时间? (django)

[英]Get last_login time for a certain user? (django)

I have the code User.objects.values_list('last_login',flat= True) Which gives me a list of all of the last logins for all of the users but I'm unsure how you slim that done to a specific user. 我有代码User.objects.values_list('last_login',flat= True)该代码为我提供了所有用户的所有最近一次登录的列表,但我不确定如何限制特定用户的操作。 I tried code along the lines of User.objects.get(username='user1').values_list('last_login',flat= True) But that didn't work. 我尝试了User.objects.get(username='user1').values_list('last_login',flat= True)但这User.objects.get(username='user1').values_list('last_login',flat= True) I think I need something between the first set of paren's and values_list but I not sure what I would put there in order for them to link up? 我想我需要在第一组paren和values_list之间添加一些内容,但是我不确定我将在其中放置什么以便它们链接起来?

Try this: 尝试这个:

user = User.objects.get(username='user1')
last_login = user.last_login

As you look at Django docs values_list is under Methods that return new QuerySets . 当您查看Django docs docs values_list ,该方法位于返回新QuerySet的Methods下。 So it is not applicable on single object as you did. 因此它不适用于单个对象。 And last_login is field of User model so you can access it directly by, 并且last_loginUser模型的字段,因此您可以通过以下方式直接访问它:

User.objects.get(username='user1').last_login

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每次我尝试将用户添加到数据库时,Django中的date_joined和last_login都会出现错误 - date_joined and last_login required error in Django every time i tried to add a User to the database 无法更新Django内置用户的last_login字段 - Unable to Update last_login field of Django in-built user 在 Django 中显示加入日期和 last_login - Display join date and last_login in Django 获取所有用户的last_login吗? - Get last_login for all users? 自定义user_logged_in信号之前django更新last_login - Custom user_logged_in signal BEFORE django updates last_login 从Django 1.6(南方)升级到1.8不会修改用户表上的“last_login” - Upgrading from Django 1.6 (with south) to 1.8 doesn't modify 'last_login' on the user table 如何更改自定义Django用户创建的数据库列last_login的名称? - How to change the name of db column last_login created by custom Django user? Django:'字段列表'中的未知列'last_login' - Django: Unknown column 'last_login' in 'field list' django-registration(1048,“Column'last_login'不能为null”) - django-registration (1048, “Column 'last_login' cannot be null”) django 将 last_login 从 DateTimeField 更改为 IntegerField - django change last_login from DateTimeField to IntegerField
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM