Skip to main content

Tracks the time of users' last actions.

Project description

Tracks the time of each user’s last action

Using middleware, django-online-users will keep track of each user and the timestamp of their last action in the database.

Admins can see this data in the admin portal, and the database can be queried using timedeltas.

This is meant for smaller applications as each HTTP request will result in a database entry update.


  • Python: 2.7, 3.3, 3.4, 3.5, 3.6
  • Django: 1.10+


  1. Add “online_users” to your INSTALLED_APPS
  1. Add the OnlineNowMiddleware to your MIDDLEWARE_CLASSES after the SessionMiddleware
  1. Run python migrate to create the tables in the database.


from datetime import timedelta
user_activity_objects = OnlineUserActivity.get_user_activities()
number_of_active_users = user_activity_objects.count()
  • A timedelta can also be specified to the get_user_activities() with to find activity
from datetime import timedelta
user_activity_objects = OnlineUserActivity.get_user_activities(timedelta(minutes=60)
users = (user for user in user_activity_objects)


OnlineUserActivity holds two values: user, the user in question, and last_activity, a timestamp stored as a DateTimeField.

OnlineUserActivity.get_user_activities() will return OnlineUserActivity objects for the last 15 minutes by default. Developers can also pass in a time delta of a different length of time for the query. The response is a QuerySet containing the active users during that time period, and the items are sorted in descending chronological order.

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-online-users, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size django_online_users-0.1-py3-none-any.whl (8.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-online-users-0.1.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View
Filename, size django_online_users-0.3-py2-none-any.whl (9.2 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size django_online_users-0.3-py3-none-any.whl (9.2 kB) File type Wheel Python version 3.5 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page