Hi all,
I trying to retrive the request.session values into the forms.py 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!
<!-- forms.py -->
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})
self.fields['is_active'].widget.attrs.update({'class':'form-check-input'})