list all active Sessions when using django-user-sessions

Viewed 439

I'm currently working on a django project and I'm using the django-user-sessions library. This library overrides the django contrib Sessions and offers possibilities for user session management.

What I want to do is to list all active sessions, with the default django Session it would be something like this :

Session.objects.filter(session__expire_date__gt=datetime.now())

The problem is I can't do it when I use django-user-sessions because we have to turn off the use of the default Sessions. All I could do with it is list a user's sessions

user.session_set.filter(expire_date__gt=datetime.now())

Please, if you are familiare with this library can you guide me? Already checked the documentation but it doesn't tell how.

I want to be able to import the Session class from this library.

1 Answers

I just found the solution by analyzing the django-user-sessions library's code. The Session class is simply in the lib's models at user_sessions_path/models.py. To import it and use it to list all sessions :

user_sessions.models.Session.objects.filter(expire_date__gt=datetime.now())
Related