您需要
last_activity在用户个人资料(或自定义用户模型)中包含该字段。该字段将根据每个请求进行更新。为此,您需要自定义中间件:
个人资料/middleware.py:
from django.utils import timezonefrom myproject.profiles.models import Profileclass UpdateLastActivityMiddleware(object): def process_view(self, request, view_func, view_args, view_kwargs): assert hasattr(request, 'user'), 'The UpdateLastActivityMiddleware requires authentication middleware to be installed.' if request.user.is_authenticated(): Profile.objects.filter(user__id=request.user.id) .update(last_activity=timezone.now())
将此中间件添加到您的设置文件中:
MIDDLEWARE_CLASSES = ( # other middlewares 'myproject.profiles.middleware.UpdateLastActivityMiddleware',)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)