Django - 扩展登录功能以保存最后一个登录日期时间

时间:2013-08-24 21:45:42

标签: python django django-views django-authentication

我需要存储有关用户的其他信息:最后一个用户登录的数据。 我的想法是对登录功能执行更新以正确存储此信息。 当我使用通用的django登录功能时,我想在不改变现在工作的情况下执行它。

我的自定义用户模型:

class ExtendedUser(models.Model):
    user = models.OneToOneField(User)
    lbo_login = models.DateTimeField(auto_now_add = True)

我的urls.py(调用内置登录功能)

url(r'^accounts/login/$', 'django.contrib.auth.views.login'),

我的想法:

# login function
# ...
# Before storing the information of the current login, 
# Something like:
user.extendeduser.lbo_login = user.last_login
user.extendeduser.save()
# continue with the login function and update the last login field
你可以帮帮我吗?如何补充内置功能? 感谢。

1 个答案:

答案 0 :(得分:1)