Django tracking recent online users

Is there a way to track active users in django?

I saw several online solutions to the problem:

http://mpcabd.igeex.biz/get-online-users-in-django/

is one of them. But it seems rather strange to modify the structure of the model only to solve this simple problem. I would like to know if there is a quick fix.

The last_login field in django auth is also not very useful, since it only logs the user's login time, and the field is not updated if the user has been in the session for a long time

+6
django session
source share
4 answers

I am the one who wrote this blog :)

I did not modify the User model, I expanded it, it is the same as profiles, but I wanted to make it so that if you already defined a profile, you can still use my method.

I think that expanding the User model is the best way to handle this; I don't know if there are any points against this.

+4
source share

I agree that the best way to do this is to use a profile. This will have a foreign key for the Users table, and not modify the existing table.

In terms of how to record user actions, one template might be a decorator that wraps all the views you want to record. The decorator simply recorded time and action against the corresponding user profile.

+4
source share

Changing the auth user model This is probably not a very "flexible" approach.

The easiest way to do this is to possibly provide a profile. Django has built-in support for providing a user profile model for storing additional user data without the need to change any built-in model.

See the Django manual

You would just save the last active time in the user profile.

+2
source share

Try this solution:

  • Create a profile model using user.id as a foreign key.
  • Create a profile view when a user logs in, change status from offline to online

    • You can also use the view to check the last users registered in 'X' minutes.
  • Handle when a window closes using jquery or when it logs out of the "profile profile" to change the state from the network to offline

0
source share

All Articles