On May 19, 12:31 pm, EmileZola <marc....@gmail.com> wrote: > I want to list the logged in users on my index page and was wondering > what was the right way to do this. > > Can I do it similar to this ? > def index(request): > return render_to_response('index.html', { > 'online_users': User.objects.filter(last_login > delay) > }) > delay being "now - 15 minutes" or something like that... > > Is there a way to use is_authenticated() in that context ? > Should I use a MiddleWare instead to acheive this ? >
I don't think basing it off of last_login will work, because they may login and then stay logged in for 2 weeks or whatever you have your cookie settings set to. I have a piece of middleware that maintains a dictionary of username, datetime key/value pairs in the cache. If the requesting user is authenticated I update their timestamp in the dictionary. I then iterate over the dictionary and delete entries that are older than some threshold. I then have a template tag that retrieves the dictionary from the cache and displays the names. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.