Is there any way to track active users in django?
I have seen a few online solutions to the problem:
http://mpcabd.igeex.biz/get-online-users-in-django/
being one of those. But it seems rather odd to modify the model structure just to solve this simple problem. I would like to know if there is any quick solution around.
The last_login field in django auth is also not of much use since it only records the time when a user logs in and the field is not updated if the user has been in session for a long time
But the correct way to check if a user is logged in or not is to use : request. user. is_authenticated. This will return True if the person is logged in other wise False.
Enter the username and password of the superuser you just created with the manage.py command to log in. Next, you will see the Django admin dashboard. The "User visit log" has already been added to the Admin. Click on the "User visits" link.
Write a piece of Javascript which will send a dummy request to server. Put this to repeat on say 60 or some seconds. As long as you are receiving requests you know page is on. Then you can check if that user is authenticated.
I'm the one who wrote that blog :)
I didn't modify the User model, I extended it, it is the same as profiles, but I wanted to make it in a way that if you have already defined a profile you can still use my method.
I think extending the User model is the best way to handle it, I don't know if there are any points against it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With