Skip to content
Back to Blog

Django track user activity

Rich Jones

Feb 24, 2017 10:00:00 AM

Tiny blog post!

Do you want to find the most recently logged in users in your Django application? Cool, no problem. You'll be filtering and sorting your most active users in no time.

Here's how you do it:

  from django.contrib.auth.models import User
  users = User.objects.order_by('-last_login')
view raw hosted with ❤ by GitHub


Then, to display the result,

view raw loggedin.html hosted with ❤ by GitHub


And that's it! Handy little trick if you're trying to engage your active users with each other.


Written By:

Rich Jones

Want to get our totally not sh*tty weekly newsletter?

Sometimes The Wayfarer is funny, sometimes insightful, but always the least spammy newsletter this side of Tatooine.