I started exploring this, but quickly hit the roadblock of how to get the session associated with a particular user. This is not easily done - the only way I can see doing it is to iterate over all session objects, decode them and check for the user id. That seems like a lot of overhead with the relatively small payoff of showing whether a user is online or not.
All in all, I think you're right though, that this would be the way to go if I wanted to stick with existing tools. There may be a way to get something wrapped around the session framework to populate another table with the user id and delete it on logout or expiration. I'll have to mess around a bit more. - Tim On Feb 21, 12:53 pm, Chris Czub <[email protected]> wrote: > If you are using default Django sessions, they will be stored in the database. > > From the docs: > By default, Django stores sessions in your database (using the model > django.contrib.sessions.models.Session). Though this is convenient, in > some setups it's faster to store session data elsewhere, so Django can > be configured to store session data on your filesystem or in your > cache. > > >>> from django.contrib.sessions.models import Session > >>> Session.objects.all() > > [<Session: Session object>, <Session: Session object>, <Session: > Session object>, <Session: Session object>, <Session: Session object>, > <Session: Session object>, <Session: Session object>, <Session: > Session object>, <Session: Session object>, <Session: Session object>, > <Session: Session object>, <Session: Session object>, <Session: > Session object>, <Session: Session object>, <Session: Session object>, > <Session: Session object>, <Session: Session object>, <Session: > Session object>, <Session: Session object>, <Session: Session object>, > '...(remaining elements truncated)...']>>> > Session.objects.all()[0].get_decoded() > > {'_auth_user_id': 1L, '_auth_user_backend': > 'django.contrib.auth.backends.ModelBackend'} > > On Sat, Feb 21, 2009 at 12:27 PM, Tim <[email protected]> wrote: > > > Hi - > > > I am using the Django auth backend and I'd like to test which users > > are currently logged in. I can't do this just by grabbing > > User.objects.all() and testing each with is_authenticated, because the > > User objects being User objects as opposed to AnonymousUser objects > > will always return True for is_authenticated. Can anyone point me to > > the right way to do this? > > > - Tim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

