14👍
✅
user_logged_in
signal is connected to django.contrib.auth.models.update_last_login
function, it makes:
user.last_login = timezone.now()
user.save(update_fields=['last_login'])
0👍
I think the best way of doing this thing is
request_user, data = requests.get_parameters(request)
user = requests.get_user_by_username(data['username'])
update_last_login(None, user)
You can also get user for request object by doing following.
user = request.user
0👍
on djnago 1.11
add this class :
class IsAuthenticated(BasePermission):
"""
Allows access only to authenticated users.
"""
def has_permission(self, request, view):
if request.user and request.user.is_authenticated:
user = request.user
user.last_login = timezone.now()
user.save(update_fields=['last_login'])
return request.user and request.user.is_authenticated
on setting file change :
'DEFAULT_PERMISSION_CLASSES': (
# custom class
'IsAuthenticated',
),
- Mix View and ViewSet in a browsable api_root
- Next previous links from a query set / generic views
- Django request Post json
- FastCGI application behind NGINX is unable to detect that HTTPS secure connection is used
- Custom save method on model – django
Source:stackexchange.com