class ImpersonateMiddleware(object):

    def process_request(self, request):
        if request.user.is_superuser and '__impersonate' in request.GET:
            request.session['impersonate_id'] = int(request.GET[
                '__impersonate'])
Django user impersonation by admin