How to access request.session into the

Hi all,

I trying to retrive the request.session values into the to perform the condition for username class.
I need to avoid the request.user, disable yourself, but it can disable other users
Is there any chance to have request.session values here or other solution to manipulate the class in this scenario?!? Thanks!

<!-- -->
class CustomUserChangeForm(UserChangeForm):
    class Meta:
        model = CustomUser

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        for field in self.fields:
            self.fields[field].widget.attrs['class'] = 'form-control'
        # trying to do something like this
        if request.session.username == self.instance.username:
            self.fields['is_active'].widget.attrs.update({'class':'form-check-input, 'disabled':True})

There was a thread not too long ago about this. Take a look at Using request.user in and see if that helps.

That’s what I’m looking for! I’ll see how it goes. Thanks again!