Created
July 20, 2015 14:23
-
-
Save melizeche/9155f599b171f6334248 to your computer and use it in GitHub Desktop.
How to ban/kick a logged in user in django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.sessions.models import Session | |
from django.contrib.auth.models import User | |
# grab the user in question | |
user = User.objects.get(username='johndoe') | |
[s.delete() for s in Session.objects.all() if s.get_decoded().get('_auth_user_id') == user.id] | |
user.is_active = False | |
user.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can run this from Django shell
./manage.py shell